Input / Output Driver APIs¶
ADC Interface¶
-
static void
adc_enable
(struct device *dev)¶ Enable ADC hardware.
This routine enables the ADC hardware block for data sampling for the specified device.
- Return
- N/A
- Parameters
dev
: Pointer to the device structure for the driver instance.
-
static void
adc_disable
(struct device *dev)¶ Disable ADC hardware.
This routine disables the ADC hardware block for data sampling for the specified device.
- Return
- N/A
- Parameters
dev
: Pointer to the device structure for the driver instance.
-
static int
adc_read
(struct device *dev, struct adc_seq_table *seq_table)¶ Set a read request.
This routine sends a read or sampling request to the ADC hardware block. A sequence table describes the read request. The routine returns once the ADC completes the read sequence. The sample data can be retrieved from the memory buffers in the sequence table structure.
- Parameters
dev
: Pointer to the device structure for the driver instance.seq_table
: Pointer to the structure representing the sequence table.
- Return Value
0
: On successelse
: Otherwise.
-
struct
adc_seq_entry
¶ - #include <adc.h>
ADC driver Sequence entry.
This structure defines a sequence entry used to define a sample from a specific channel.
-
struct
adc_seq_table
¶ - #include <adc.h>
ADC driver Sequence table.
This structure defines a list of sequence entries used to execute a sequence of samplings.
-
struct
adc_driver_api
¶ - #include <adc.h>
ADC driver API.
This structure holds all API function pointers.
GPIO Interface¶
-
typedef
gpio_callback_handler_t
¶ Define the application callback handler function signature.
Note: cb pointer can be used to retrieve private data through CONTAINER_OF() if original struct gpio_callback is stored in another private structure.
- Parameters
struct device *port
: Device struct for the GPIO device.struct gpio_callback *cb
: Original struct gpio_callback owning this handleruint32_t pins
: Mask of pins that triggers the callback handler
-
static int
gpio_pin_configure
(struct device *port, uint8_t pin, int flags)¶ Configure a single pin.
- Return
- 0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to device structure for the driver instance.pin
: Pin number to configure.flags
: Flags for pin configuration. IN/OUT, interrupt ...
-
static int
gpio_pin_write
(struct device *port, uint32_t pin, uint32_t value)¶ Write the data value to a single pin.
- Return
- 0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.pin
: Pin number where the data is written.value
: Value set on the pin.
-
static int
gpio_pin_read
(struct device *port, uint32_t pin, uint32_t *value)¶ Read the data value of a single pin.
Read the input state of a pin, returning the value 0 or 1.
- Return
- 0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.pin
: Pin number where data is read.value
: Integer pointer to receive the data values from the pin.
-
static void
gpio_init_callback
(struct gpio_callback *callback, gpio_callback_handler_t handler, uint32_t pin_mask)¶ Helper to initialize a struct gpio_callback properly.
- Parameters
callback
: A valid Application’s callback structure pointer.handler
: A valid handler function pointer.pin_mask
: A bit mask of relevant pins for the handler
-
static int
gpio_add_callback
(struct device *port, struct gpio_callback *callback)¶ Add an application callback.
Note: enables to add as many callback as needed on the same port.
- Return
- 0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.callback
: A valid Application’s callback structure pointer.
-
static int
gpio_remove_callback
(struct device *port, struct gpio_callback *callback)¶ Remove an application callback.
Note: enables to remove as many callbacks as added through gpio_add_callback().
- Return
- 0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.callback
: A valid application’s callback structure pointer.
-
static int
gpio_pin_enable_callback
(struct device *port, uint32_t pin)¶ Enable callback(s) for a single pin.
Note: Depending on the driver implementation, this function will enable the pin to trigger an interruption. So as a semantic detail, if no callback is registered, of course none will be called.
- Return
- 0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.pin
: Pin number where the callback function is enabled.
-
static int
gpio_pin_disable_callback
(struct device *port, uint32_t pin)¶ Disable callback(s) for a single pin.
- Return
- 0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.pin
: Pin number where the callback function is disabled.
-
static int
gpio_port_configure
(struct device *port, int flags)¶ Configure all the pins the same way in the port. List out all flags on the detailed description.
- Return
- 0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.flags
: Flags for the port configuration. IN/OUT, interrupt ...
-
static int
gpio_port_write
(struct device *port, uint32_t value)¶ Write a data value to the port.
Write the output state of a port. The state of each pin is represented by one bit in the value. Pin 0 corresponds to the least signficiant bit, pin 31 corresponds to the most significant bit. For ports with less that 32 physical pins the most signficant bits which do not correspond to a physical pin are ignored.
- Return
- 0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.value
: Value to set on the port.
-
static int
gpio_port_read
(struct device *port, uint32_t *value)¶ Read data value from the port.
Read the input state of a port. The state of each pin is represented by one bit in the returned value. Pin 0 corresponds to the least signficiant bit, pin 31 corresponds to the most significant bit. Unused bits for ports with less that 32 physical pins are returned as 0.
- Return
- 0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.value
: Integer pointer to receive the data value from the port.
-
static int
gpio_port_enable_callback
(struct device *port)¶ Enable callback(s) for the port.
Note: Depending on the driver implementation, this function will enable the port to trigger an interruption on all pins, as long as these are configured properly. So as a semantic detail, if no callback is registered, of course none will be called.
- Return
- 0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.
-
static int
gpio_port_disable_callback
(struct device *port)¶ Disable callback(s) for the port.
- Return
- 0 if successful, negative errno code on failure.
- Parameters
port
: Pointer to the device structure for the driver instance.
-
static int
gpio_get_pending_int
(struct device *dev)¶ Function to get pending interrupts.
The purpose of this function is to return the interrupt status register for the device. This is especially useful when waking up from low power states to check the wake up source.
- Parameters
dev
: Pointer to the device structure for the driver instance.
- Return Value
status
: != 0 if at least one gpio interrupt is pending.0
: if no gpio interrupt is pending.
-
GPIO_DIR_IN
(0 << 0)¶ GPIO pin to be input.
-
GPIO_DIR_OUT
(1 << 0)¶ GPIO pin to be output.
-
GPIO_INT
(1 << 1)¶ GPIO pin to trigger interrupt.
-
GPIO_INT_ACTIVE_LOW
(0 << 2)¶ GPIO pin trigger on level low or falling edge.
-
GPIO_INT_ACTIVE_HIGH
(1 << 2)¶ GPIO pin trigger on level high or rising edge.
-
GPIO_INT_CLOCK_SYNC
(1 << 3)¶ GPIO pin trigger to be synchronized to clock pulses.
-
GPIO_INT_DEBOUNCE
(1 << 4)¶ Enable GPIO pin debounce.
-
GPIO_INT_LEVEL
(0 << 5)¶ Do Level trigger.
-
GPIO_INT_EDGE
(1 << 5)¶ Do Edge trigger.
-
GPIO_INT_DOUBLE_EDGE
(1 << 6)¶ Interrupt triggers on both rising and falling edge.
-
GPIO_POL_NORMAL
(0 << GPIO_POL_POS)¶ GPIO pin polarity is normal.
-
GPIO_POL_INV
(1 << GPIO_POL_POS)¶ GPIO pin polarity is inverted.
-
GPIO_PUD_NORMAL
(0 << GPIO_PUD_POS)¶ GPIO pin to have no pull-up or pull-down.
-
GPIO_PUD_PULL_UP
(1 << GPIO_PUD_POS)¶ Enable GPIO pin pull-up.
-
GPIO_PUD_PULL_DOWN
(2 << GPIO_PUD_POS)¶ Enable GPIO pin pull-down.
-
GPIO_PIN_ENABLE
(1 << 10)¶ Enable GPIO pin.
-
GPIO_PIN_DISABLE
(1 << 11)¶ Disable GPIO pin.
-
GPIO_DS_DFLT_LOW
(0x0 << GPIO_DS_LOW_POS)¶ Default drive strength standard when GPIO pin output is low.
-
GPIO_DS_ALT_LOW
(0x1 << GPIO_DS_LOW_POS)¶ Alternative drive strength when GPIO pin output is low. For hardware that does not support configurable drive strength use the default drive strength.
-
GPIO_DS_DISCONNECT_LOW
(0x3 << GPIO_DS_LOW_POS)¶ Disconnect pin when GPIO pin output is low. For hardware that does not support disconnect use the default drive strength.
-
GPIO_DS_DFLT_HIGH
(0x0 << GPIO_DS_HIGH_POS)¶ Default drive strength when GPIO pin output is high.
-
GPIO_DS_ALT_HIGH
(0x1 << GPIO_DS_HIGH_POS)¶ Alternative drive strength when GPIO pin output is high. For hardware that does not support configurable drive strengths use the default drive strength.
-
GPIO_DS_DISCONNECT_HIGH
(0x3 << GPIO_DS_HIGH_POS)¶ Disconnect pin when GPIO pin output is high. For hardware that does not support disconnect use the default drive strength.
-
GPIO_DECLARE_PIN_CONFIG_IDX
(_idx) struct gpio_pin_config gpio_pin_ ##_idx¶
-
GPIO_DECLARE_PIN_CONFIG
GPIO_DECLARE_PIN_CONFIG_IDX()¶
-
GPIO_PIN_IDX
(_idx, _controller, _pin) .gpio_pin_ ##_idx = { \ .gpio_controller = (_controller),\ .gpio_pin = (_pin), \ }¶
-
GPIO_PIN
(_controller, _pin) GPIO_PIN_IDX(, _controller, _pin)¶
-
GPIO_GET_CONTROLLER_IDX
(_idx, _conf) ((_conf)->gpio_pin_ ##_idx.gpio_controller)¶
-
GPIO_GET_PIN_IDX
(_idx, _conf) ((_conf)->gpio_pin_ ##_idx.gpio_pin)¶
-
GPIO_GET_CONTROLLER
(_conf) GPIO_GET_CONTROLLER_IDX(, _conf)¶
-
GPIO_GET_PIN
(_conf) GPIO_GET_PIN_IDX(, _conf)¶
-
struct
gpio_callback
¶ - #include <gpio.h>
GPIO callback structure.
Used to register a callback in the driver instance callback list. As many callbacks as needed can be added as long as each of them are unique pointers of struct gpio_callback. Beware such structure should not be allocated on stack.
Note: To help setting it, see gpio_init_callback() below
I2C Interface¶
-
static int
i2c_configure
(struct device *dev, uint32_t dev_config)¶ Configure operation of a host controller.
- Parameters
dev
: Pointer to the device structure for the driver instance.dev_config
: Bit-packed 32-bit value to the device runtime configuration for the I2C controller.
- Return Value
0
: If successful.-EIO
: General input / output error, failed to configure device.
-
static int
i2c_write
(struct device *dev, uint8_t *buf, uint32_t num_bytes, uint16_t addr)¶ Write a set amount of data to an I2C device.
This routine writes a set amount of data synchronously.
- Parameters
dev
: Pointer to the device structure for the driver instance.buf
: Memory pool from which the data is transferred.num_bytes
: Number of bytes to write.addr
: Address to the target I2C device for writing.
- Return Value
0
: If successful.-EIO
: General input / output error.
-
static int
i2c_read
(struct device *dev, uint8_t *buf, uint32_t num_bytes, uint16_t addr)¶ Read a set amount of data from an I2C device.
This routine reads a set amount of data synchronously.
- Parameters
dev
: Pointer to the device structure for the driver instance.buf
: Memory pool that stores the retrieved data.num_bytes
: Number of bytes to read.addr
: Address of the I2C device being read.
- Return Value
0
: If successful.-EIO
: General input / output error.
-
static int
i2c_transfer
(struct device *dev, struct i2c_msg *msgs, uint8_t num_msgs, uint16_t addr)¶ Perform data transfer to another I2C device.
This routine provides a generic interface to perform data transfer to another I2C device synchronously. Use i2c_read()/i2c_write() for simple read or write.
The array of message msgs must not be NULL. The number of message num_msgs may be zero,in which case no transfer occurs.
- Parameters
dev
: Pointer to the device structure for the driver instance.msgs
: Array of messages to transfer.num_msgs
: Number of messages to transfer.addr
: Address of the I2C target device.
- Return Value
0
: If successful.-EIO
: General input / output error.
-
static int
i2c_burst_read
(struct device *dev, uint16_t dev_addr, uint8_t start_addr, uint8_t *buf, uint8_t num_bytes)¶ Read multiple bytes from an internal address of an I2C device.
This routine reads multiple bytes from an internal address of an I2C device synchronously.
- Parameters
dev
: Pointer to the device structure for the driver instance.dev_addr
: Address of the I2C device for reading.start_addr
: Internal address from which the data is being read.buf
: Memory pool that stores the retrieved data.num_bytes
: Number of bytes being read.
- Return Value
0
: If successful.-EIO
: General input / output error.
-
static int
i2c_burst_write
(struct device *dev, uint16_t dev_addr, uint8_t start_addr, uint8_t *buf, uint8_t num_bytes)¶ Write multiple bytes to an internal address of an I2C device.
This routine writes multiple bytes to an internal address of an I2C device synchronously.
- Parameters
dev
: Pointer to the device structure for the driver instance.dev_addr
: Address of the I2C device for writing.start_addr
: Internal address to which the data is being written.buf
: Memory pool from which the data is transferred.num_bytes
: Number of bytes being written.
- Return Value
0
: If successful.-EIO
: General input / output error.
-
static int
i2c_reg_read_byte
(struct device *dev, uint16_t dev_addr, uint8_t reg_addr, uint8_t *value)¶ Read internal register of an I2C device.
This routine reads the value of an 8-bit internal register of an I2C device synchronously.
- Parameters
dev
: Pointer to the device structure for the driver instance.dev_addr
: Address of the I2C device for reading.reg_addr
: Address of the internal register being read.value
: Memory pool that stores the retrieved register value.
- Return Value
0
: If successful.-EIO
: General input / output error.
-
static int
i2c_reg_write_byte
(struct device *dev, uint16_t dev_addr, uint8_t reg_addr, uint8_t value)¶ Write internal register of an I2C device.
This routine writes a value to an 8-bit internal register of an I2C device synchronously.
- Parameters
dev
: Pointer to the device structure for the driver instance.dev_addr
: Address of the I2C device for writing.reg_addr
: Address of the internal register being written.value
: Value to be written to internal register.
- Return Value
0
: If successful.-EIO
: General input / output error.
-
static int
i2c_reg_update_byte
(struct device *dev, uint8_t dev_addr, uint8_t reg_addr, uint8_t mask, uint8_t value)¶ Update internal register of an I2C device.
This routine updates the value of a set of bits from an 8-bit internal register of an I2C device synchronously.
- Parameters
dev
: Pointer to the device structure for the driver instance.dev_addr
: Address of the I2C device for updating.reg_addr
: Address of the internal register being updated.mask
: Bitmask for updating internal register.value
: Value for updating internal register.
- Return Value
0
: If successful.-EIO
: General input / output error.
-
static int
i2c_burst_read16
(struct device *dev, uint16_t dev_addr, uint16_t start_addr, uint8_t *buf, uint8_t num_bytes)¶ Read multiple bytes from an internal 16 bit address of an I2C device.
This routine reads multiple bytes from a 16 bit internal address of an I2C device synchronously.
- Parameters
dev
: Pointer to the device structure for the driver instance.dev_addr
: Address of the I2C device for reading.start_addr
: Internal 16 bit address from which the data is being read.buf
: Memory pool that stores the retrieved data.num_bytes
: Number of bytes being read.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
i2c_burst_write16
(struct device *dev, uint16_t dev_addr, uint16_t start_addr, uint8_t *buf, uint8_t num_bytes)¶ Write multiple bytes to a 16 bit internal address of an I2C device.
This routine writes multiple bytes to a 16 bit internal address of an I2C device synchronously.
- Parameters
dev
: Pointer to the device structure for the driver instance.dev_addr
: Address of the I2C device for writing.start_addr
: Internal 16 bit address to which the data is being written.buf
: Memory pool from which the data is transferred.num_bytes
: Number of bytes being written.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
i2c_reg_read16
(struct device *dev, uint16_t dev_addr, uint16_t reg_addr, uint8_t *value)¶ Read internal 16 bit address register of an I2C device.
This routine reads the value of an 16-bit internal register of an I2C device synchronously.
- Parameters
dev
: Pointer to the device structure for the driver instance.dev_addr
: Address of the I2C device for reading.reg_addr
: 16 bit address of the internal register being read.value
: Memory pool that stores the retrieved register value.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
i2c_reg_write16
(struct device *dev, uint16_t dev_addr, uint16_t reg_addr, uint8_t value)¶ Write internal 16 bit address register of an I2C device.
This routine writes a value to an 16-bit internal register of an I2C device synchronously.
- Parameters
dev
: Pointer to the device structure for the driver instance.dev_addr
: Address of the I2C device for writing.reg_addr
: 16 bit address of the internal register being written.value
: Value to be written to internal register.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
i2c_reg_update16
(struct device *dev, uint16_t dev_addr, uint16_t reg_addr, uint8_t mask, uint8_t value)¶ Update internal 16 bit address register of an I2C device.
This routine updates the value of a set of bits from a 16-bit internal register of an I2C device synchronously.
- Parameters
dev
: Pointer to the device structure for the driver instance.dev_addr
: Address of the I2C device for updating.reg_addr
: 16 bit address of the internal register being updated.mask
: Bitmask for updating internal register.value
: Value for updating internal register.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
i2c_burst_read_addr
(struct device *dev, uint16_t dev_addr, uint8_t *start_addr, const uint8_t addr_size, uint8_t *buf, uint8_t num_bytes)¶ Read multiple bytes from an internal variable byte size address of an I2C device.
This routine reads multiple bytes from an addr_size byte internal address of an I2C device synchronously.
- Parameters
dev
: Pointer to the device structure for the driver instance.dev_addr
: Address of the I2C device for reading.start_addr
: Array to an internal register address from which the data is being read.addr_size
: Size in bytes of the register address.buf
: Memory pool that stores the retrieved data.num_bytes
: Number of bytes being read.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
i2c_burst_write_addr
(struct device *dev, uint16_t dev_addr, uint8_t *start_addr, const uint8_t addr_size, uint8_t *buf, uint8_t num_bytes)¶ Write multiple bytes to an internal variable bytes size address of an I2C device. This routine writes multiple bytes to an addr_size byte internal address of an I2C device synchronously.
- Parameters
dev
: Pointer to the device structure for the driver instance.dev_addr
: Address of the I2C device for writing.start_addr
: Array to an internal register address from which the data is being read.addr_size
: Size in bytes of the register address.buf
: Memory pool from which the data is transferred.num_bytes
: Number of bytes being written.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
i2c_reg_read_addr
(struct device *dev, uint16_t dev_addr, uint8_t *reg_addr, const uint8_t addr_size, uint8_t *value)¶ Read internal variable byte size address register of an I2C device.
This routine reads the value of an addr_size byte internal register of an I2C device synchronously.
- Parameters
dev
: Pointer to the device structure for the driver instance.dev_addr
: Address of the I2C device for reading.reg_addr
: Array to an internal register address from which the data is being read.addr_size
: Size in bytes of the register address.value
: Memory pool that stores the retrieved register value.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
i2c_reg_write_addr
(struct device *dev, uint16_t dev_addr, uint8_t *reg_addr, const uint8_t addr_size, uint8_t value)¶ Write internal variable byte size address register of an I2C device.
This routine writes a value to an addr_size byte internal register of an I2C device synchronously.
- Parameters
dev
: Pointer to the device structure for the driver instance.dev_addr
: Address of the I2C device for writing.reg_addr
: Array to an internal register address from which the data is being read.addr_size
: Size in bytes of the register address.value
: Value to be written to internal register.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
i2c_reg_update_addr
(struct device *dev, uint16_t dev_addr, uint8_t *reg_addr, uint8_t addr_size, uint8_t mask, uint8_t value)¶ Update internal variable byte size address register of an I2C device.
This routine updates the value of a set of bits from a addr_size byte internal register of an I2C device synchronously.
- Parameters
dev
: Pointer to the device structure for the driver instance.dev_addr
: Address of the I2C device for updating.reg_addr
: Array to an internal register address from which the data is being read.addr_size
: Size in bytes of the register address.mask
: Bitmask for updating internal register.value
: Value for updating internal register.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
I2C_SPEED_STANDARD
(0x1)¶ I2C Standard Speed
-
I2C_SPEED_FAST
(0x2)¶ I2C Fast Speed
-
I2C_SPEED_FAST_PLUS
(0x3)¶ I2C Fast Plus Speed
-
I2C_SPEED_HIGH
(0x4)¶ I2C High Speed
-
I2C_SPEED_ULTRA
(0x5)¶ I2C Ultra Fast Speed
-
I2C_ADDR_10_BITS
(1 << 0)¶ Use 10-bit addressing.
-
I2C_MODE_MASTER
(1 << 4)¶ Controller to act as Master.
-
I2C_MODE_SLAVE_READ
(1 << 5)¶ Controller to act as Slave.
-
I2C_MSG_WRITE
(0 << 0)¶ Write message to I2C bus.
-
I2C_MSG_READ
(1 << 0)¶ Read message from I2C bus.
-
I2C_MSG_STOP
(1 << 1)¶ Send STOP after this message.
-
I2C_MSG_RESTART
(1 << 2)¶ RESTART I2C transaction for this message.
-
I2C_DECLARE_CLIENT_CONFIG
struct i2c_client_config i2c_client¶
-
I2C_CLIENT
(_master, _addr) .i2c_client = { \ .i2c_master = (_master), \ .i2c_addr = (_addr), \ }¶
-
I2C_GET_MASTER
(_conf) ((_conf)->i2c_client.i2c_master)¶
-
I2C_GET_ADDR
(_conf) ((_conf)->i2c_client.i2c_addr)¶
-
struct
i2c_msg
¶ - #include <i2c.h>
One I2C Message.
This defines one I2C message to transact on the I2C bus.
-
union
dev_config
¶ - #include <i2c.h>
IPM Interface¶
-
typedef
ipm_callback_t
¶ Callback API for incoming IPM messages.
These callbacks execute in interrupt context. Therefore, use only interrupt-safe APIS. Registration of callbacks is done via ipm_register_callback
- Parameters
void *context
: Arbitrary context pointer provided at registration time.uint32_t id
: Message type identifier.volatile void *data
: Message data pointer. The correct amount of data to read out must be inferred using the message id/upper level protocol.
-
typedef
ipm_send_t
¶ Callback API to send IPM messages.
See ipm_send() for argument definitions.
-
typedef
ipm_max_data_size_get_t
¶ Callback API to get maximum data size.
See ipm_max_data_size_get() for argument definitions.
-
typedef
ipm_max_id_val_get_t
¶ Callback API to get the ID’s maximum value.
See ipm_max_id_val_get() for argument definitions.
-
typedef
ipm_register_callback_t
¶ Callback API upon registration.
See ipm_register_callback() for argument definitions.
-
typedef
ipm_set_enabled_t
¶ Callback API upon emablement of interrupts.
See ipm_set_enabled() for argument definitions.
-
static int
ipm_send
(struct device *ipmdev, int wait, uint32_t id, const void *data, int size)¶ Try to send a message over the IPM device.
A message is considered consumed once the remote interrupt handler finishes. If there is deferred processing on the remote side, or if outgoing messages must be queued and wait on an event/semaphore, a high-level driver can implement that.
There are constraints on how much data can be sent or the maximum value of id. Use the ipm_max_data_size_get and ipm_max_id_val_get routines to determine them.
The size parameter is used only on the sending side to determine the amount of data to put in the message registers. It is not passed along to the receiving side. The upper-level protocol dictates the amount of data read back.
- Parameters
ipmdev
: Driver instancewait
: If nonzero, busy-wait for remote to consume the message. The message is considered consumed once the remote interrupt handler finishes. If there is deferred processing on the remote side, or you would like to queue outgoing messages and wait on an event/semaphore, you can implement that in a high-level driverid
: Message identifier. Values are constrained by ipm_max_data_size_get since many boards only allow for a subset of bits in a 32-bit register to store the ID.data
: Pointer to the data sent in the message.size
: Size of the data.
- Return Value
EBUSY
: If the remote hasn’t yet read the last data sent.EMSGSIZE
: If the supplied data size is unsupported by the driver.EINVAL
: If there was a bad parameter, such as: too-large id value. or the device isn’t an outbound IPM channel.0
: On success.
-
static void
ipm_register_callback
(struct device *ipmdev, ipm_callback_t cb, void *context)¶ Register a callback function for incoming messages.
- Parameters
ipmdev
: Driver instance pointer.cb
: Callback function to execute on incoming message interrupts.context
: Application-specific context pointer which will be passed to the callback function when executed.
-
static int
ipm_max_data_size_get
(struct device *ipmdev)¶ Return the maximum number of bytes possible in an outbound message.
IPM implementations vary on the amount of data that can be sent in a single message since the data payload is typically stored in registers.
- Return
- Maximum possible size of a message in bytes.
- Parameters
ipmdev
: Driver instance pointer.
-
static uint32_t
ipm_max_id_val_get
(struct device *ipmdev)¶ Return the maximum id value possible in an outbound message.
Many IPM implementations store the message’s ID in a register with some bits reserved for other uses.
- Return
- Maximum possible value of a message ID.
- Parameters
ipmdev
: Driver instance pointer.
PWM Interface¶
-
typedef
pwm_config_t
¶ Callback API upon configuration See pwm_pin_configure() for argument description.
-
typedef
pwm_set_values_t
¶ Callback API upon setting PIN values See pwm_pin_set_values() for argument description.
-
typedef
pwm_set_duty_cycle_t
¶ Callback API upon setting the duty cycle See pwm_pin_set_duty_cycle() for argument description.
-
typedef
pwm_set_phase_t
¶ Callback API upon setting the phase See pwm_pin_set_phase() for argument description.
-
typedef
pwm_set_period_t
¶ Callback API upon setting the period See pwm_pin_set_period() for argument description.
-
typedef
pwm_pin_set_t
¶ Callback API upon setting the pin See pwm_pin_set_cycles() for argument description.
-
typedef
pwm_get_cycles_per_sec_t
¶ Callback API upon getting cycles per second See pwm_get_cycles_per_sec() for argument description.
-
static int
pwm_pin_set_cycles
(struct device *dev, uint32_t pwm, uint32_t period, uint32_t pulse)¶ Set the period and pulse width for a single PWM output.
- Parameters
dev
: Pointer to the device structure for the driver instance.pwm
: PWM pin.period
: Period (in clock cycle) set to the PWM. HW specific.pulse
: Pulse width (in clock cycle) set to the PWM. HW specific.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
pwm_pin_set_usec
(struct device *dev, uint32_t pwm, uint32_t period, uint32_t pulse)¶ Set the period and pulse width for a single PWM output.
- Parameters
dev
: Pointer to the device structure for the driver instance.pwm
: PWM pin.period
: Period (in micro second) set to the PWM.pulse
: Pulse width (in micro second) set to the PWM.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
pwm_get_cycles_per_sec
(struct device *dev, uint32_t pwm, uint64_t *cycles)¶ Get the clock rate (cycles per second) for a single PWM output.
- Parameters
dev
: Pointer to the device structure for the driver instance.pwm
: PWM pin.cycles
: Pointer to the memory to store clock rate (cycles per sec). HW specific.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
pwm_pin_configure
(struct device *dev, uint8_t pwm, int flags)¶ Configure a single PWM output.
- Parameters
dev
: Pointer to the device structure for the driver instance.pwm
: PWM output.flags
: PWM configuration flags.
- Return Value
0
: If successful,Negative
: errno code if failure.
-
static int
pwm_pin_set_values
(struct device *dev, uint32_t pwm, uint32_t on, uint32_t off)¶ Set the ON/OFF values for a single PWM output.
- Parameters
dev
: Pointer to the device structure for the driver instance.pwm
: PWM output.on
: ON value (number of timer count) set to the PWM. HW specific. How far from the beginning of a PWM cycle the PWM pulse starts.off
: OFF value (number of timer count) set to the PWM. HW specific. How far from the beginning of a PWM cycle the PWM pulse stops.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
pwm_pin_set_period
(struct device *dev, uint32_t pwm, uint32_t period)¶ Set the period of a single PWM output.
It is optional to call this API. If not called, there is a default period.
- Parameters
dev
: Pointer to the device structure for the driver instance.pwm
: PWM output.period
: Period duration of the cycle to set in microseconds
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
pwm_pin_set_duty_cycle
(struct device *dev, uint32_t pwm, uint8_t duty)¶ Set the duty cycle of a single PWM output.
This routine overrides any ON/OFF values set before.
- Parameters
dev
: Pointer to the device structure for the driver instance.pwm
: PWM output.duty
: Duty cycle to set to the PWM in %, for example, 50 sets to 50%.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
pwm_pin_set_phase
(struct device *dev, uint32_t pwm, uint8_t phase)¶ Set the phase of a single PWM output.
This routine sets the delay before pulses.
- Parameters
dev
: Pointer to the device structure for the driver instance.pwm
: PWM output.phase
: The number of clock ticks to delay before the start of pulses.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
pwm_all_configure
(struct device *dev, int flags)¶ Configure all the PWM outputs.
- Parameters
dev
: Pointer to the device structure for the driver instance.flags
: PWM configuration flags.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
pwm_all_set_values
(struct device *dev, uint32_t on, uint32_t off)¶ Set the ON/OFF values for all PWM outputs.
- Parameters
dev
: Pointer to the device structure for the driver instance.on
: ON value (number of timer count) set to the PWM. HW specific. How far from the beginning of a PWM cycle the PWM pulse starts.off
: OFF value (number of timer count) set to the PWM. HW specific. How far from the beginning of a PWM cycle the PWM pulse stops.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
pwm_all_period
(struct device *dev, uint32_t period)¶ Set the period of all PWM outputs.
It is optional to call this API. If not called, there is a default period.
- Parameters
dev
: Pointer to the device structure for the driver instance.period
: Period duration of the cycle to set in microseconds
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
pwm_all_set_duty_cycle
(struct device *dev, uint8_t duty)¶ Set the duty cycle of all PWM outputs.
This overrides any ON/OFF values being set before.
- Parameters
dev
: Pointer to the device structure for the driver instance.duty
: Duty cycle to set to the PWM in %, for example, 50 sets to 50%.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
pwm_all_set_phase
(struct device *dev, uint8_t phase)¶ Set the phase of all PWM outputs.
This routine sets the delay before pulses.
- Parameters
dev
: Pointer to the device structure for the driver instance.phase
: The number of clock ticks to delay before the start of pulses.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
PWM_ACCESS_BY_PIN
0¶
-
PWM_ACCESS_ALL
1¶
-
struct
pwm_driver_api
¶ - #include <pwm.h>
PWM driver API definition.
Pinmux Interface¶
-
typedef
pmux_set
¶ Callback API upon setting a PIN’s function See pinmux_pin_set() for argument description.
-
typedef
pmux_get
¶ Callback API upon getting a PIN’s function See pinmux_pin_get() for argument description.
-
typedef
pmux_pullup
¶ Callback API upon setting a PIN’s pullup See pinmix_pin_pullup() for argument description.
-
typedef
pmux_input
¶ Callback API upon setting a PIN’s input function See pinmux_input() for argument description.
-
PINMUX_FUNC_A
0¶
-
PINMUX_FUNC_B
1¶
-
PINMUX_FUNC_C
2¶
-
PINMUX_FUNC_D
3¶
-
PINMUX_PULLUP_ENABLE
(0x1)¶
-
PINMUX_PULLUP_DISABLE
(0x0)¶
-
PINMUX_INPUT_ENABLED
(0x1)¶
-
PINMUX_OUTPUT_ENABLED
(0x0)¶
SPI Interface¶
-
typedef
spi_api_configure
¶ Callback API upon configuring the const controller See spi_configure() for argument description.
-
typedef
spi_api_slave_select
¶ Callback API upon selecting a slave See spi_slave_select() for argument description.
-
typedef
spi_api_io
¶ Callback API for I/O See spi_read() and spi_write() for argument descriptions.
-
static int
spi_configure
(struct device *dev, struct spi_config *config)¶ Configure a host controller for operating against slaves.
- Parameters
dev
: Pointer to the device structure for the driver instance.config
: Pointer to the configuration provided by the application.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
spi_slave_select
(struct device *dev, uint32_t slave)¶ Select a slave to deal with.
This routine is meaningful only if the controller supports per-slave addressing: One SS line per-slave. If not, this routine has no effect and daisy-chaining should be considered to deal with multiple slaves on the same line.
- Parameters
dev
: Pointer to the device structure for the driver instanceslave
: An integer identifying the slave. It starts from 1 which corresponds to cs0.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
spi_read
(struct device *dev, void *buf, uint32_t len)¶ Read the specified amount of data from the SPI driver.
- Parameters
dev
: Pointer to the device structure for the driver instance.buf
: Memory buffer where data will be transferred.len
: Size of the memory buffer available for writing.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
spi_write
(struct device *dev, const void *buf, uint32_t len)¶ Write the specified amount of data from the SPI driver.
- Parameters
dev
: Pointer to the device structure for the driver instance.buf
: Memory buffer from where data is transferred.len
: Size of the memory buffer available for reading.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
static int
spi_transceive
(struct device *dev, const void *tx_buf, uint32_t tx_buf_len, void *rx_buf, uint32_t rx_buf_len)¶ Read and write the specified amount of data from the SPI driver.
This routine is meant for full-duplex transmission. Only equal length is supported(tx_buf_len must be equal to rx_buf_len).
- Parameters
dev
: Pointer to the device structure for the driver instance.tx_buf
: Memory buffer where data originatestx_buf_len
: Size of the memory buffer available for reading.rx_buf
: Memory buffer where data is transferred.rx_buf_len
: Size of the memory buffer available for writing.
- Return Value
0
: If successful.Negative
: errno code if failure.
-
SPI_MODE_CPOL
0x1¶ SPI Polarity & Phase Modes.
-
SPI_MODE_CPHA
0x2¶
-
SPI_MODE_LOOP
0x4¶
-
SPI_MODE_MASK
(0x7)¶
-
SPI_MODE
(_in_) ((_in_) & SPI_MODE_MASK)¶
-
SPI_TRANSFER_MSB
(0 << 3)¶ SPI Transfer modes (host controller dependent)
-
SPI_TRANSFER_LSB
(1 << 3)¶
-
SPI_TRANSFER_MASK
(0x8)¶
-
SPI_WORD_SIZE_MASK
(0xFF << 4)¶
-
SPI_WORD_SIZE_GET
(_in_) (((_in_) & SPI_WORD_SIZE_MASK) >> 4)¶
-
SPI_WORD
(_in_) ((_in_) << 4)¶
-
struct
spi_config
¶ - #include <spi.h>
SPI configuration structure.
config is a bit field with the following parts: mode [ 0 : 2 ] - Polarity, phase and loop mode. transfer_mode [ 3 ] - LSB or MSB first transfer mode. word_size [ 4 : 11 ] - Size of a data frame in bits. RESERVED [ 12 : 31 ] - Undefined or device-specific usage.
max_sys_freq is the clock divider supported by the the host spi controller.
Random Interface¶
-
typedef
random_get_entropy_t
¶ Callback API to get entropy.
See random_get_entropy() for argument description
-
static int
random_get_entropy
(struct device *dev, uint8_t *buffer, uint16_t length)¶ Get entropy from the random driver.
Fill a buffer with entropy from the random driver.
- Parameters
dev
: Pointer to the random device.buffer
: Buffer to fill with entropy.length
: Buffer length.
- Return Value
0
: on success.-ERRNO
: errno code on error.
UART Interface¶
-
typedef
uart_irq_callback_t
¶ Define the application callback function signature for UART.
- Parameters
port
: Device struct for the UART device.
-
typedef
uart_irq_config_func_t
¶ For configuring IRQ on each individual UART device.
-
static int
uart_err_check
(struct device *dev)¶ Check whether an error was detected.
- Parameters
dev
: UART device structure.
- Return Value
UART_ERROR_OVERRUN
: if an overrun error was detected.UART_ERROR_PARITY
: if a parity error was detected.UART_ERROR_FRAMING
: if a framing error was detected.UART_ERROR_BREAK
: if a break error was detected.0
: Otherwise.
-
static int
uart_poll_in
(struct device *dev, unsigned char *p_char)¶ Poll the device for input.
- Parameters
dev
: UART device structure.p_char
: Pointer to character.
- Return Value
0
: If a character arrived.-1
: If no character was available to read (i.e., the UART input buffer was empty).-ENOTSUP
: If the operation is not supported.
-
static unsigned char
uart_poll_out
(struct device *dev, unsigned char out_char)¶ Output a character in polled mode.
This routine checks if the transmitter is empty. When the transmitter is empty, it writes a character to the data register.
To send a character when hardware flow control is enabled, the handshake signal CTS must be asserted.
- Parameters
dev
: UART device structure.out_char
: Character to send.
- Return Value
char
: Sent character.
-
static int
uart_fifo_fill
(struct device *dev, const uint8_t *tx_data, int size)¶ Fill FIFO with data.
- Return
- Number of bytes sent.
- Parameters
dev
: UART device structure.tx_data
: Data to transmit.size
: Number of bytes to send.
-
static int
uart_fifo_read
(struct device *dev, uint8_t *rx_data, const int size)¶ Read data from FIFO.
- Return
- Number of bytes read.
- Parameters
dev
: UART device structure.rx_data
: Data container.size
: Container size.
-
static void
uart_irq_tx_enable
(struct device *dev)¶ Enable TX interrupt in IER.
- Return
- N/A
- Parameters
dev
: UART device structure.
-
static void
uart_irq_tx_disable
(struct device *dev)¶ Disable TX interrupt in IER.
- Return
- N/A
- Parameters
dev
: UART device structure.
-
static int
uart_irq_tx_ready
(struct device *dev)¶ Check if Tx IRQ has been raised.
- Parameters
dev
: UART device structure.
- Return Value
1
: If an IRQ is ready.0
: Otherwise.
-
static void
uart_irq_rx_enable
(struct device *dev)¶ Enable RX interrupt in IER.
- Return
- N/A
- Parameters
dev
: UART device structure.
-
static void
uart_irq_rx_disable
(struct device *dev)¶ Disable RX interrupt in IER.
- Return
- N/A
- Parameters
dev
: UART device structure.
-
static int
uart_irq_tx_empty
(struct device *dev)¶ Check if nothing remains to be transmitted.
- Parameters
dev
: UART device structure.
- Return Value
1
: If nothing remains to be transmitted.0
: Otherwise.
-
static int
uart_irq_rx_ready
(struct device *dev)¶ Check if Rx IRQ has been raised.
- Parameters
dev
: UART device structure.
- Return Value
1
: If an IRQ is ready.0
: Otherwise.
-
static void
uart_irq_err_enable
(struct device *dev)¶ Enable error interrupt in IER.
- Return
- N/A
- Parameters
dev
: UART device structure.
-
static void
uart_irq_err_disable
(struct device *dev)¶ Disable error interrupt in IER.
- Parameters
dev
: UART device structure.
- Return Value
1
: If an IRQ is ready.0
: Otherwise.
-
static int
uart_irq_is_pending
(struct device *dev)¶ Check if any IRQs is pending.
- Parameters
dev
: UART device structure.
- Return Value
1
: If an IRQ is pending.0
: Otherwise.
-
static int
uart_irq_update
(struct device *dev)¶ Update cached contents of IIR.
- Parameters
dev
: UART device structure.
- Return Value
1
: Always.
-
static void
uart_irq_callback_set
(struct device *dev, uart_irq_callback_t cb)¶ Set the IRQ callback function pointer.
This sets up the callback for IRQ. When an IRQ is triggered, the specified function will be called.
- Return
- N/A
- Parameters
dev
: UART device structure.cb
: Pointer to the callback function.
-
static int
uart_drv_cmd
(struct device *dev, uint32_t cmd, uint32_t p)¶ Send extra command to driver.
Implementation and accepted commands are driver specific. Refer to the drivers for more information.
- Parameters
dev
: UART device structure.cmd
: Command to driver.p
: Parameter to the command.
- Return Value
0
: If successful.failed
: Otherwise.
-
UART_OPTION_AFCE
0x01¶ Options for UART initialization.
-
LINE_CTRL_BAUD_RATE
(1 << 0)¶ Common line controls for UART.
-
LINE_CTRL_RTS
(1 << 1)¶
-
LINE_CTRL_DTR
(1 << 2)¶
-
LINE_CTRL_DCD
(1 << 3)¶
-
LINE_CTRL_DSR
(1 << 4)¶
-
UART_ERROR_OVERRUN
(1 << 0)¶ Overrun error.
-
UART_ERROR_PARITY
(1 << 1)¶ Parity error.
-
UART_ERROR_FRAMING
(1 << 2)¶ Framing error.
-
UART_ERROR_BREAK
(1 << 3)¶ Break interrupt error:
A break interrupt was received. This happens when the serial input is held at a logic ‘0’ state for longer than the sum of start time + data bits
- parity + stop bits.
-
struct
uart_device_config
¶ - #include <uart.h>
UART device configuration.
- Parameters
port
: Base port numberbase
: Memory mapped base addressregs
: Register addresssys_clk_freq
: System clock frequency in Hz
- union
Public Members
-
-
struct
uart_driver_api
¶ - #include <uart.h>
Driver API structure.
Sensor Interface¶
-
enum
sensor_interface::
sensor_channel
¶ Sensor channels.
Values:
-
SENSOR_CHAN_ACCEL_X
¶ Acceleration on the X axis, in m/s^2.
-
SENSOR_CHAN_ACCEL_Y
¶ Acceleration on the Y axis, in m/s^2.
-
SENSOR_CHAN_ACCEL_Z
¶ Acceleration on the Z axis, in m/s^2.
-
SENSOR_CHAN_ACCEL_XYZ
¶ Acceleration on the X, Y and Z axes.
-
SENSOR_CHAN_ACCEL_ANY
= SENSOR_CHAN_ACCEL_XYZ¶ This enum value will be deprecated. Please use SENSOR_CHAN_ACCEL_XYZ instead.
Acceleration on any axis.
-
SENSOR_CHAN_GYRO_X
¶ Angular velocity around the X axis, in radians/s.
-
SENSOR_CHAN_GYRO_Y
¶ Angular velocity around the Y axis, in radians/s.
-
SENSOR_CHAN_GYRO_Z
¶ Angular velocity around the Z axis, in radians/s.
-
SENSOR_CHAN_GYRO_XYZ
¶ Angular velocity around the X, Y and Z axes.
-
SENSOR_CHAN_GYRO_ANY
= SENSOR_CHAN_GYRO_XYZ¶ This enum value will be deprecated. Please use SENSOR_CHAN_GYRO_XYZ instead.
Angular velocity on any axis.
-
SENSOR_CHAN_MAGN_X
¶ Magnetic field on the X axis, in Gauss.
-
SENSOR_CHAN_MAGN_Y
¶ Magnetic field on the Y axis, in Gauss.
-
SENSOR_CHAN_MAGN_Z
¶ Magnetic field on the Z axis, in Gauss.
-
SENSOR_CHAN_MAGN_XYZ
¶ Magnetic field on the X, Y and Z axes.
-
SENSOR_CHAN_MAGN_ANY
= SENSOR_CHAN_MAGN_XYZ¶ This enum value will be deprecated. Please use SENSOR_CHAN_MAGN_XYZ instead.
Magnetic field on any axis.
-
SENSOR_CHAN_TEMP
¶ Temperature in degrees Celsius.
-
SENSOR_CHAN_PRESS
¶ Pressure in kilopascal.
-
SENSOR_CHAN_PROX
¶ Proximity. Adimensional. A value of 1 indicates that an object is close.
-
SENSOR_CHAN_HUMIDITY
¶ Humidity, in milli percent.
-
SENSOR_CHAN_LIGHT
¶ Illuminance in visible spectrum, in lux.
-
SENSOR_CHAN_IR
¶ Illuminance in infra-red spectrum, in lux.
-
SENSOR_CHAN_ALTITUDE
¶ Altitude, in meters
-
SENSOR_CHAN_ALL
¶ All channels.
-
-
enum
sensor_interface::
sensor_trigger_type
¶ Sensor trigger types.
Values:
-
SENSOR_TRIG_TIMER
¶ Timer-based trigger, useful when the sensor does not have an interrupt line.
-
SENSOR_TRIG_DATA_READY
¶ Trigger fires whenever new data is ready.
-
SENSOR_TRIG_DELTA
¶ Trigger fires when the selected channel varies significantly. This includes any-motion detection when the channel is acceleration or gyro. If detection is based on slope between successive channel readings, the slope threshold is configured via the SENSOR_ATTR_SLOPE_TH and SENSOR_ATTR_SLOPE_DUR attributes.
-
SENSOR_TRIG_NEAR_FAR
¶ Trigger fires when a near/far event is detected.
-
SENSOR_TRIG_THRESHOLD
¶ Trigger fires when channel reading transitions configured thresholds. The thresholds are configured via the SENSOR_ATTR_LOWER_THRESH and SENSOR_ATTR_UPPER_THRESH attributes.
-
SENSOR_TRIG_TAP
¶ Trigger fires when a single tap is detected.
-
SENSOR_TRIG_DOUBLE_TAP
¶ Trigger fires when a double tap is detected.
-
-
enum
sensor_interface::
sensor_attribute
¶ Sensor attribute types.
Values:
-
SENSOR_ATTR_SAMPLING_FREQUENCY
¶ Sensor sampling frequency, i.e. how many times a second the sensor takes a measurement.
-
SENSOR_ATTR_LOWER_THRESH
¶ Lower threshold for trigger.
-
SENSOR_ATTR_UPPER_THRESH
¶ Upper threshold for trigger.
-
SENSOR_ATTR_SLOPE_TH
¶ Threshold for any-motion (slope) trigger.
-
SENSOR_ATTR_SLOPE_DUR
¶ Duration for which the slope values needs to be outside the threshold for the trigger to fire.
-
SENSOR_ATTR_OVERSAMPLING
¶ Oversampling factor
-
SENSOR_ATTR_FULL_SCALE
¶ Sensor range, in SI units.
-
SENSOR_ATTR_OFFSET
¶ The sensor value returned will be altered by the amount indicated by offset: final_value = sensor_value + offset.
-
SENSOR_ATTR_CALIB_TARGET
¶ Calibration target. This will be used by the internal chip’s algorithms to calibrate itself on a certain axis, or all of them.
-
-
typedef
sensor_trigger_handler_t
¶ Callback API upon firing of a trigger.
- Parameters
struct device *dev
: Pointer to the sensor devicestruct sensor_trigger *trigger
: The trigger
-
typedef
sensor_attr_set_t
¶ Callback API upon setting a sensor’s attributes.
See sensor_attr_set() for argument description
-
typedef
sensor_trigger_set_t
¶ Callback API for setting a sensor’s trigger and handler.
See sensor_trigger_set() for argument description
-
typedef
sensor_sample_fetch_t
¶ Callback API for fetching data from a sensor.
See sensor_sample_fetch() for argument description
-
typedef
sensor_channel_get_t
¶ Callback API for getting a reading from a sensor.
See sensor_channel_get() for argument description
-
static int
sensor_attr_set
(struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val)¶ Set an attribute for a sensor.
- Return
- 0 if successful, negative errno code if failure.
- Parameters
dev
: Pointer to the sensor devicechan
: The channel the attribute belongs to, if any. Some attributes may only be set for all channels of a device, depending on device capabilities.attr
: The attribute to setval
: The value to set the attribute to
-
static int
sensor_trigger_set
(struct device *dev, struct sensor_trigger *trig, sensor_trigger_handler_t handler)¶ Activate a sensor’s trigger and set the trigger handler.
The handler will be called from a fiber, so I2C or SPI operations are safe. However, the fiber’s stack is limited and defined by the driver. It is currently up to the caller to ensure that the handler does not overflow the stack.
- Return
- 0 if successful, negative errno code if failure.
- Parameters
dev
: Pointer to the sensor devicetrig
: The trigger to activatehandler
: The function that should be called when the trigger fires
-
static int
sensor_sample_fetch
(struct device *dev)¶ Fetch a sample from the sensor and store it in an internal driver buffer.
Read all of a sensor’s active channels and, if necessary, perform any additional operations necessary to make the values useful. The user may then get individual channel values by calling sensor_channel_get.
Since the function communicates with the sensor device, it is unsafe to call it in an ISR if the device is connected via I2C or SPI.
- Return
- 0 if successful, negative errno code if failure.
- Parameters
dev
: Pointer to the sensor device
-
static int
sensor_sample_fetch_chan
(struct device *dev, enum sensor_channel type)¶ Fetch a sample from the sensor and store it in an internal driver buffer.
Read and compute compensation for one type of sensor data (magnetometer, accelerometer, etc). The user may then get individual channel values by calling sensor_channel_get.
This is mostly implemented by multi function devices enabling reading at different sampling rates.
Since the function communicates with the sensor device, it is unsafe to call it in an ISR if the device is connected via I2C or SPI.
- Return
- 0 if successful, negative errno code if failure.
- Parameters
dev
: Pointer to the sensor devicetype
: The channel that needs updated
-
static int
sensor_channel_get
(struct device *dev, enum sensor_channel chan, struct sensor_value *val)¶ Get a reading from a sensor device.
Return a useful value for a particular channel, from the driver’s internal data. Before calling this function, a sample must be obtained by calling sensor_sample_fetch or sensor_sample_fetch_chan. It is guaranteed that two subsequent calls of this function for the same channels will yield the same value, if sensor_sample_fetch or sensor_sample_fetch_chan has not been called in the meantime.
For vectorial data samples you can request all axes in just one call by passing the specific channel with _XYZ suffix. The sample will be returned at val[0], val[1] and val[2] (X, Y and Z in that order).
- Return
- 0 if successful, negative errno code if failure.
- Parameters
dev
: Pointer to the sensor devicechan
: The channel to readval
: Where to store the value
-
static int32_t
sensor_ms2_to_g
(const struct sensor_value *ms2)¶ Helper function to convert acceleration from m/s^2 to Gs.
- Return
- The converted value, in Gs.
- Parameters
ms2
: A pointer to a sensor_value struct holding the acceleration, in m/s^2.
-
static void
sensor_g_to_ms2
(int32_t g, struct sensor_value *ms2)¶ Helper function to convert acceleration from Gs to m/s^2.
- Parameters
g
: The G value to be converted.ms2
: A pointer to a sensor_value struct, where the result is stored.
-
static int32_t
sensor_rad_to_degrees
(const struct sensor_value *rad)¶ Helper function for converting radians to degrees.
- Return
- The converted value, in degrees.
- Parameters
rad
: A pointer to a sensor_value struct, holding the value in radians.
-
static void
sensor_degrees_to_rad
(int32_t d, struct sensor_value *rad)¶ Helper function for converting degrees to radians.
- Parameters
d
: The value (in degrees) to be converted.rad
: A pointer to a sensor_value struct, where the result is stored.
-
static double
sensor_value_to_double
(struct sensor_value *val)¶ Helper function for converting struct sensor_value to double.
- Return
- The converted value.
- Parameters
val
: A pointer to a sensor_value struct.
-
SENSOR_G
9806650LL¶ The value of gravitational constant in micro m/s^2.
-
SENSOR_PI
3141592LL¶ The value of constant PI in micros.
-
struct
sensor_value
¶ - #include <sensor.h>
Representation of a sensor readout value.
The value is represented as having an integer and a fractional part, and can be obtained using the formula val1 + val2 * 10^(-6).
-
struct
sensor_trigger
¶ - #include <sensor.h>
Sensor trigger spec.