peripheralman: Update APIs in accordance with Android Things
Signed-off-by: Sanrio Alvares <sanrio.alvares@intel.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
@@ -187,7 +187,7 @@ cmake -DRPM=ON -DCMAKE_INSTALL_PREFIX=/usr ..
|
||||
|
||||
## Building for Peripheralmanager Android Things
|
||||
|
||||
Change src/CMakeLists.txt:146 to the location of libperipheralman.so on your
|
||||
Change src/CMakeLists.txt:146 to the location of libandroidthings.so on your
|
||||
machine or have it in your Android NDK. Switch the toolchain file var to point
|
||||
to where your Android NDK is (here android-ndk is in /opt).
|
||||
|
||||
|
||||
@@ -29,76 +29,76 @@ __BEGIN_DECLS
|
||||
/// @{
|
||||
|
||||
/// Edge trigger types.
|
||||
enum {
|
||||
NONE_EDGE, /**< None */
|
||||
RISING_EDGE, /**< Rising edge */
|
||||
FALLING_EDGE, /**< Falling edge */
|
||||
BOTH_EDGE /**< Both edges */
|
||||
};
|
||||
typedef enum AGpioEdge {
|
||||
AGPIO_EDGE_NONE = 0, /**< None */
|
||||
AGPIO_EDGE_RISING = 1, /**< Rising edge */
|
||||
AGPIO_EDGE_FALLING = 2, /**< Falling edge */
|
||||
AGPIO_EDGE_BOTH = 3 /**< Both edges */
|
||||
} AGpioEdge;
|
||||
|
||||
/// GPIO direction types.
|
||||
enum {
|
||||
DIRECTION_IN, /**< Input mode */
|
||||
DIRECTION_OUT_INITIALLY_HIGH, /**< Output mode, initially set to high */
|
||||
DIRECTION_OUT_INITIALLY_LOW /**< Output mode, initially set to low */
|
||||
};
|
||||
typedef enum AGpioDirection {
|
||||
AGPIO_DIRECTION_IN = 0, /**< Input mode */
|
||||
AGPIO_DIRECTION_OUT_INITIALLY_HIGH = 1, /**< Output mode, initially high */
|
||||
AGPIO_DIRECTION_OUT_INITIALLY_LOW = 2 /**< Output mode, initially low */
|
||||
} AGpioDirection;
|
||||
|
||||
/// Possible active types.
|
||||
enum {
|
||||
ACTIVE_LOW, /**< Active Low */
|
||||
ACTIVE_HIGH /**< Active High */
|
||||
};
|
||||
typedef enum AGpioActiveType {
|
||||
AGPIO_ACTIVE_LOW = 0, /**< Active Low */
|
||||
AGPIO_ACTIVE_HIGH = 1 /**< Active High */
|
||||
} AGpioActiveType;
|
||||
|
||||
typedef struct BGpio BGpio;
|
||||
typedef struct AGpio AGpio;
|
||||
|
||||
/// Sets the GPIO direction to output.
|
||||
/// @param gpio Pointer to the BGpio struct
|
||||
/// @param gpio Pointer to the AGpio struct
|
||||
/// @param direction One of DIRECTION_IN,
|
||||
/// DIRECTION_OUT_INITIALLY_HIGH, DIRECTION_OUT_INITIALLY_LOW.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BGpio_setDirection(const BGpio* gpio, int direction);
|
||||
int AGpio_setDirection(const AGpio* gpio, AGpioDirection direction);
|
||||
|
||||
/// Sets the interrupt edge trigger type.
|
||||
/// @param gpio Pointer to the BGpio struct
|
||||
/// @param gpio Pointer to the AGpio struct
|
||||
/// @param type One of NONE_EDGE, RISING_EDGE, FALLING_EDGE or BOTH_EDGE.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BGpio_setEdgeTriggerType(const BGpio* gpio, int type);
|
||||
int AGpio_setEdgeTriggerType(const AGpio* gpio, AGpioEdge type);
|
||||
|
||||
/// Sets the GPIO’s active low/high status.
|
||||
/// @param gpio Pointer to the BGpio struct.
|
||||
/// @param gpio Pointer to the AGpio struct.
|
||||
/// @param type One of ACTIVE_HIGH, ACTIVE_LOW.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BGpio_setActiveType(const BGpio* gpio, int type);
|
||||
int AGpio_setActiveType(const AGpio* gpio, AGpioActiveType type);
|
||||
|
||||
/// Sets the GPIO value (for output GPIO only).
|
||||
/// @param gpio Pointer to the BGpio struct.
|
||||
/// @param gpio Pointer to the AGpio struct.
|
||||
/// @param value Value to set.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BGpio_setValue(const BGpio* gpio, int value);
|
||||
int AGpio_setValue(const AGpio* gpio, int value);
|
||||
|
||||
/// Gets the GPIO value (for input GPIO only).
|
||||
/// @param gpio Pointer to the BGpio struct.
|
||||
/// @param gpio Pointer to the AGpio struct.
|
||||
/// @param value Output pointer to the value of the GPIO.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BGpio_getValue(const BGpio* gpio, int* value);
|
||||
int AGpio_getValue(const AGpio* gpio, int* value);
|
||||
|
||||
/// Returns a file descriptor that can be used to poll on new data.
|
||||
/// Can be passed to select/epoll to wait for data to become available.
|
||||
/// @param gpio Pointer to the BGpio struct.
|
||||
/// @param gpio Pointer to the AGpio struct.
|
||||
/// @param fd Output pointer to the file descriptor number.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BGpio_getPollingFd(const BGpio* gpio, int* fd);
|
||||
int AGpio_getPollingFd(const AGpio* gpio, int* fd);
|
||||
|
||||
/// Acknowledges the interrupt and resets the file descriptor.
|
||||
/// This must be called after each event triggers in order to be able to
|
||||
/// poll/select for another event.
|
||||
/// @param fd Polling file descriptor to reset.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BGpio_ackInterruptEvent(int fd);
|
||||
int AGpio_ackInterruptEvent(int fd);
|
||||
|
||||
/// Destroys a BGpio struct.
|
||||
/// @param gpio Pointer to the BGpio struct.
|
||||
void BGpio_delete(BGpio* gpio);
|
||||
/// Destroys a AGpio struct.
|
||||
/// @param gpio Pointer to the AGpio struct.
|
||||
void AGpio_delete(AGpio* gpio);
|
||||
|
||||
/// @}
|
||||
|
||||
|
||||
@@ -28,79 +28,79 @@ __BEGIN_DECLS
|
||||
/// These functions can be used to control an I2C device.
|
||||
/// @{
|
||||
|
||||
typedef struct BI2cDevice BI2cDevice;
|
||||
typedef struct AI2cDevice AI2cDevice;
|
||||
|
||||
/// Reads from the device.
|
||||
/// @param device Pointer to the BI2cDevice struct.
|
||||
/// @param device Pointer to the AI2cDevice struct.
|
||||
/// @param data Output buffer to write the data to.
|
||||
/// @param len Number of bytes to read.
|
||||
/// @return 0 on success, errno on error
|
||||
int BI2cDevice_read(const BI2cDevice* device, void* data, uint32_t len);
|
||||
int AI2cDevice_read(const AI2cDevice* device, void* data, uint32_t len);
|
||||
|
||||
/// Reads a byte from an I2C register.
|
||||
/// @param device Pointer to the BI2cDevice struct.
|
||||
/// @param device Pointer to the AI2cDevice struct.
|
||||
/// @param reg Register to read from.
|
||||
/// @param val Output pointer to value to read.
|
||||
/// @return 0 on success, errno on error
|
||||
int BI2cDevice_readRegByte(const BI2cDevice* device, uint8_t reg, uint8_t* val);
|
||||
int AI2cDevice_readRegByte(const AI2cDevice* device, uint8_t reg, uint8_t* val);
|
||||
|
||||
/// Reads a word from an I2C register.
|
||||
/// @param device Pointer to the BI2cDevice struct.
|
||||
/// @param device Pointer to the AI2cDevice struct.
|
||||
/// @param reg Register to read from.
|
||||
/// @param val Output pointer to value to read.
|
||||
/// @return 0 on success, errno on error
|
||||
int BI2cDevice_readRegWord(const BI2cDevice* device,
|
||||
int AI2cDevice_readRegWord(const AI2cDevice* device,
|
||||
uint8_t reg,
|
||||
uint16_t* val);
|
||||
|
||||
/// Reads from an I2C register.
|
||||
/// @param device Pointer to the BI2cDevice struct.
|
||||
/// @param device Pointer to the AI2cDevice struct.
|
||||
/// @param reg Register to read from.
|
||||
/// @param data Output buffer to write the data to.
|
||||
/// @param len Number of bytes to read.
|
||||
/// @return 0 on success, errno on error
|
||||
int BI2cDevice_readRegBuffer(const BI2cDevice* device,
|
||||
int AI2cDevice_readRegBuffer(const AI2cDevice* device,
|
||||
uint8_t reg,
|
||||
void* data,
|
||||
uint32_t len);
|
||||
|
||||
/// Writes to the device.
|
||||
/// @param device Pointer to the BI2cDevice struct.
|
||||
/// @param device Pointer to the AI2cDevice struct.
|
||||
/// @param data Buffer to write.
|
||||
/// @param len Number of bytes to write.
|
||||
/// @return 0 on success, errno on error
|
||||
int BI2cDevice_write(const BI2cDevice* device, const void* data, uint32_t len);
|
||||
int AI2cDevice_write(const AI2cDevice* device, const void* data, uint32_t len);
|
||||
|
||||
/// Writes a byte to an I2C register.
|
||||
/// @param device Pointer to the BI2cDevice struct.
|
||||
/// @param device Pointer to the AI2cDevice struct.
|
||||
/// @param reg Register to write to.
|
||||
/// @param val Value to write.
|
||||
/// @return 0 on success, errno on error
|
||||
int BI2cDevice_writeRegByte(const BI2cDevice* device, uint8_t reg, uint8_t val);
|
||||
int AI2cDevice_writeRegByte(const AI2cDevice* device, uint8_t reg, uint8_t val);
|
||||
|
||||
/// Writes a word to an I2C register.
|
||||
/// @param device Pointer to the BI2cDevice struct.
|
||||
/// @param device Pointer to the AI2cDevice struct.
|
||||
/// @param reg Register to write to.
|
||||
/// @param val Value to write.
|
||||
/// @return 0 on success, errno on error
|
||||
int BI2cDevice_writeRegWord(const BI2cDevice* device,
|
||||
int AI2cDevice_writeRegWord(const AI2cDevice* device,
|
||||
uint8_t reg,
|
||||
uint16_t val);
|
||||
|
||||
/// Writes to an I2C register.
|
||||
/// @param device Pointer to the BI2cDevice struct.
|
||||
/// @param device Pointer to the AI2cDevice struct.
|
||||
/// @param reg Register to write to.
|
||||
/// @param data Data to write.
|
||||
/// @param len Number of bytes to write.
|
||||
/// @return 0 on success, errno on error
|
||||
int BI2cDevice_writeRegBuffer(const BI2cDevice* device,
|
||||
int AI2cDevice_writeRegBuffer(const AI2cDevice* device,
|
||||
uint8_t reg,
|
||||
const void* data,
|
||||
uint32_t len);
|
||||
|
||||
/// Destroys a BI2cDevice struct.
|
||||
/// @param device Pointer to the BI2cDevice struct.
|
||||
void BI2cDevice_delete(BI2cDevice* device);
|
||||
/// Destroys a AI2cDevice struct.
|
||||
/// @param device Pointer to the AI2cDevice struct.
|
||||
void AI2cDevice_delete(AI2cDevice* device);
|
||||
|
||||
/// @}
|
||||
|
||||
|
||||
@@ -31,112 +31,108 @@ __BEGIN_DECLS
|
||||
/// @brief Functions to access embedded peripherals
|
||||
/// @{
|
||||
|
||||
typedef struct BPeripheralManagerClient BPeripheralManagerClient;
|
||||
typedef struct APeripheralManagerClient APeripheralManagerClient;
|
||||
|
||||
/// Returns the list of GPIOs.
|
||||
/// This does not take ownership into account.
|
||||
/// The list must be freed by the caller.
|
||||
/// @param client Pointer to the BPeripheralManagerClient struct.
|
||||
/// @param client Pointer to the APeripheralManagerClient struct.
|
||||
/// @param num_gpio Output pointer to the number of elements in the list.
|
||||
/// @return The list of gpios.
|
||||
char** BPeripheralManagerClient_listGpio(const BPeripheralManagerClient* client,
|
||||
char** APeripheralManagerClient_listGpio(const APeripheralManagerClient* client,
|
||||
int* num_gpio);
|
||||
|
||||
/// Opens a GPIO and takes ownership of it.
|
||||
/// @param client Pointer to the BPeripheralManagerClient struct.
|
||||
/// @param client Pointer to the APeripheralManagerClient struct.
|
||||
/// @param name Name of the GPIO.
|
||||
/// @param gpio Output pointer to the BGpio struct. Empty on error.
|
||||
/// @param gpio Output pointer to the AGpio struct. Empty on error.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BPeripheralManagerClient_openGpio(const BPeripheralManagerClient* client,
|
||||
int APeripheralManagerClient_openGpio(const APeripheralManagerClient* client,
|
||||
const char* name,
|
||||
BGpio** gpio);
|
||||
AGpio** gpio);
|
||||
|
||||
/// Returns the list of PWMs.
|
||||
/// This does not take ownership into account.
|
||||
/// The list must be freed by the caller.
|
||||
/// @param client Pointer to the BPeripheralManagerClient struct.
|
||||
/// @param client Pointer to the APeripheralManagerClient struct.
|
||||
/// @param num_gpio Output pointer to the number of elements in the list.
|
||||
/// @return The list of pwms.
|
||||
char** BPeripheralManagerClient_listPwm(const BPeripheralManagerClient* client,
|
||||
char** APeripheralManagerClient_listPwm(const APeripheralManagerClient* client,
|
||||
int* num_pwm);
|
||||
|
||||
/// Opens a PWM and takes ownership of it.
|
||||
/// @param client Pointer to the BPeripheralManagerClient struct.
|
||||
/// @param client Pointer to the APeripheralManagerClient struct.
|
||||
/// @param name Name of the PWM.
|
||||
/// @param gpio Output pointer to the BGpio struct. Empty on error.
|
||||
/// @param gpio Output pointer to the AGpio struct. Empty on error.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BPeripheralManagerClient_openPwm(const BPeripheralManagerClient* client,
|
||||
int APeripheralManagerClient_openPwm(const APeripheralManagerClient* client,
|
||||
const char* name,
|
||||
BPwm** pwm);
|
||||
APwm** pwm);
|
||||
|
||||
/// Returns the list of SPI buses.
|
||||
/// This does not take ownership into account.
|
||||
/// The list must be freed by the caller.
|
||||
/// @param client Pointer to the BPeripheralManagerClient struct.
|
||||
/// @param client Pointer to the APeripheralManagerClient struct.
|
||||
/// @param num_spi_buses Output pointer to the number of elements in the list.
|
||||
/// @return The list of spi buses.
|
||||
char** BPeripheralManagerClient_listSpiBuses(
|
||||
const BPeripheralManagerClient* client,
|
||||
int* num_spi_buses);
|
||||
char** APeripheralManagerClient_listSpiBuses(
|
||||
const APeripheralManagerClient* client, int* num_spi_buses);
|
||||
|
||||
/// Opens a SPI device and takes ownership of it.
|
||||
/// @oaram client Pointer to the BPeripheralManagerClient struct.
|
||||
/// @oaram client Pointer to the APeripheralManagerClient struct.
|
||||
/// @param name Name of the SPI device.
|
||||
/// @param dev Output pointer to the BSpiDevice struct. Empty on error.
|
||||
/// @param dev Output pointer to the ASpiDevice struct. Empty on error.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BPeripheralManagerClient_openSpiDevice(
|
||||
const BPeripheralManagerClient* client,
|
||||
const char* name,
|
||||
BSpiDevice** dev);
|
||||
int APeripheralManagerClient_openSpiDevice(
|
||||
const APeripheralManagerClient* client, const char* name, ASpiDevice** dev);
|
||||
|
||||
/// Returns the list of I2C buses.
|
||||
/// This does not take ownership into account.
|
||||
/// The list must be freed by the caller.
|
||||
/// @param client Pointer to the BPeripheralManagerClient struct.
|
||||
/// @param client Pointer to the APeripheralManagerClient struct.
|
||||
/// @param num_i2c_buses Output pointer to the number of elements in the list.
|
||||
/// @return The list of i2c buses.
|
||||
char** BPeripheralManagerClient_listI2cBuses(
|
||||
const BPeripheralManagerClient* client,
|
||||
int* num_i2c_buses);
|
||||
char** APeripheralManagerClient_listI2cBuses(
|
||||
const APeripheralManagerClient* client, int* num_i2c_buses);
|
||||
|
||||
/// Opens an I2C device and takes ownership of it.
|
||||
/// @param client Pointer to the BPeripheralManagerClient struct.
|
||||
/// @param client Pointer to the APeripheralManagerClient struct.
|
||||
/// @param name Name of the I2C bus.
|
||||
/// @param address Address of the I2C device.
|
||||
/// @param dev Output pointer to the BI2cDevice struct. Empty on error.
|
||||
/// @param dev Output pointer to the AI2cDevice struct. Empty on error.
|
||||
/// @return 0 on success, errno on error
|
||||
int BPeripheralManagerClient_openI2cDevice(
|
||||
const BPeripheralManagerClient* client,
|
||||
int APeripheralManagerClient_openI2cDevice(
|
||||
const APeripheralManagerClient* client,
|
||||
const char* name,
|
||||
uint32_t address,
|
||||
BI2cDevice** dev);
|
||||
AI2cDevice** dev);
|
||||
|
||||
/// Returns the list of UART buses.
|
||||
/// This does not take ownership into account.
|
||||
/// The list must be freed by the caller.
|
||||
/// @param client Pointer to the BPeripheralManagerClient struct.
|
||||
/// @param client Pointer to the APeripheralManagerClient struct.
|
||||
/// @param num_uart_buses Output pointer to the number of elements in the list.
|
||||
/// @return The list of uart buses.
|
||||
char** BPeripheralManagerClient_listUartDevices(
|
||||
const BPeripheralManagerClient* client, int* num_uart_buses);
|
||||
char** APeripheralManagerClient_listUartDevices(
|
||||
const APeripheralManagerClient* client, int* num_uart_buses);
|
||||
|
||||
/// Opens an UART device and takes ownership of it.
|
||||
/// @param client Pointer to the BPeripheralManagerClient struct.
|
||||
/// @param client Pointer to the APeripheralManagerClient struct.
|
||||
/// @param name Name of the UART device.
|
||||
/// @param dev Output pointer to the BUartDevice struct. Empty on error.
|
||||
/// @param dev Output pointer to the AUartDevice struct. Empty on error.
|
||||
/// @return 0 on success, errno on error
|
||||
int BPeripheralManagerClient_openUartDevice(
|
||||
const BPeripheralManagerClient* client,
|
||||
int APeripheralManagerClient_openUartDevice(
|
||||
const APeripheralManagerClient* client,
|
||||
const char* name,
|
||||
BUartDevice** dev);
|
||||
AUartDevice** dev);
|
||||
|
||||
/// Creates a new client.
|
||||
/// @return A pointer to the created client. nullptr on errors.
|
||||
BPeripheralManagerClient* BPeripheralManagerClient_new();
|
||||
APeripheralManagerClient* APeripheralManagerClient_new();
|
||||
|
||||
/// Destroys the peripheral manager client.
|
||||
/// @param client Pointer to the BPeripheralManagerClient struct.
|
||||
void BPeripheralManagerClient_delete(BPeripheralManagerClient* client);
|
||||
/// @param client Pointer to the APeripheralManagerClient struct.
|
||||
void APeripheralManagerClient_delete(APeripheralManagerClient* client);
|
||||
|
||||
/// @}
|
||||
|
||||
|
||||
@@ -28,33 +28,29 @@ __BEGIN_DECLS
|
||||
/// These functions can be used to control PWM.
|
||||
/// @{
|
||||
|
||||
typedef struct BPwm BPwm;
|
||||
typedef struct APwm APwm;
|
||||
|
||||
/// Sets the PWM duty cycle.
|
||||
/// @param gpio Pointer to the BPwm struct
|
||||
/// @param gpio Pointer to the APwm struct.
|
||||
/// @param duty_cycle Double between 0 and 100 inclusive.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BPwm_setDutyCycle(const BPwm* pwm, double duty_cycle);
|
||||
int APwm_setDutyCycle(const APwm* pwm, double duty_cycle);
|
||||
|
||||
/// Sets the PWM frequency.
|
||||
/// @param gpio Pointer to the BPwm struct
|
||||
/// @param gpio Pointer to the APwm struct.
|
||||
/// @param freq Double denoting the frequency in Hz.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BPwm_setFrequencyHz(const BPwm* pwm, double frequency);
|
||||
int APwm_setFrequencyHz(const APwm* pwm, double frequency);
|
||||
|
||||
/// Enables the PWM.
|
||||
/// @param gpio Pointer to the BPwm struct
|
||||
/// @param gpio Pointer to the APwm struct.
|
||||
/// @param enabled Non-zero to enable.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BPwm_enable(const BPwm* pwm);
|
||||
int APwm_setEnabled(const APwm* pwm, int enabled);
|
||||
|
||||
/// Disables the PWM.
|
||||
/// @param gpio Pointer to the BPwm struct
|
||||
/// @return 0 on success, errno on error.
|
||||
int BPwm_disable(const BPwm* pwm);
|
||||
|
||||
/// Destroys a BPwm struct.
|
||||
/// @param pwm Pointer to the BPwm struct.
|
||||
void BPwm_delete(BPwm* pwm);
|
||||
/// Destroys a APwm struct.
|
||||
/// @param pwm Pointer to the APwm struct.
|
||||
void APwm_delete(APwm* pwm);
|
||||
|
||||
/// @}
|
||||
|
||||
|
||||
@@ -29,96 +29,88 @@ __BEGIN_DECLS
|
||||
/// @{
|
||||
|
||||
/// Endianness.
|
||||
enum {
|
||||
SPI_LSB_FIRST, /**< Least significant bits first */
|
||||
SPI_MSB_FIRST /**< Most significant bits first */
|
||||
};
|
||||
|
||||
/// SPI phase modes.
|
||||
enum {
|
||||
SPI_CPHA = 0x01, /**< Clock phase */
|
||||
SPI_CPOL = 0x02 /**< Clock polarity */
|
||||
};
|
||||
typedef enum ASpiBitJustification {
|
||||
ASPI_LSB_FIRST = 0, /**< Least significant bits first */
|
||||
ASPI_MSB_FIRST = 1 /**< Most significant bits first */
|
||||
} ASpiBitJustification;
|
||||
|
||||
/// SPI modes (similar to the Linux kernel's modes).
|
||||
enum {
|
||||
SPI_MODE0 = 0, /**< CPHA=0, CPOL=0 */
|
||||
SPI_MODE1 = SPI_CPHA, /**< CPHA=1, CPOL=0 */
|
||||
SPI_MODE2 = SPI_CPOL, /**< CPHA=0, CPOL=1 */
|
||||
SPI_MODE3 = SPI_CPHA + SPI_CPOL /**< CPHA=1, CPOL=1 */
|
||||
};
|
||||
typedef enum ASpiMode {
|
||||
ASPI_MODE0 = 0, /**< CPHA=0, CPOL=0 */
|
||||
ASPI_MODE1 = 1, /**< CPHA=1, CPOL=0 */
|
||||
ASPI_MODE2 = 2, /**< CPHA=0, CPOL=1 */
|
||||
ASPI_MODE3 = 3 /**< CPHA=1, CPOL=1 */
|
||||
} ASpiMode;
|
||||
|
||||
typedef struct BSpiDevice BSpiDevice;
|
||||
typedef struct ASpiDevice ASpiDevice;
|
||||
|
||||
/// Writes a buffer to the device.
|
||||
/// @param device Pointer to the BSpiDevice struct.
|
||||
/// @param device Pointer to the ASpiDevice struct.
|
||||
/// @param data Buffer to write.
|
||||
/// @param len Length of the buffer.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BSpiDevice_writeBuffer(const BSpiDevice* device,
|
||||
int ASpiDevice_writeBuffer(const ASpiDevice* device,
|
||||
const void* data,
|
||||
size_t len);
|
||||
|
||||
/// Reads a buffer from the device.
|
||||
/// @param device Pointer to the BSpiDevice struct.
|
||||
/// @param device Pointer to the ASpiDevice struct.
|
||||
/// @param data Buffer to read into.
|
||||
/// @param len Length of the buffer.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BSpiDevice_readBuffer(const BSpiDevice* device,
|
||||
void* data,
|
||||
size_t len);
|
||||
int ASpiDevice_readBuffer(const ASpiDevice* device, void* data, size_t len);
|
||||
|
||||
/// Transfer data to the device.
|
||||
/// @param device Pointer to the BSpiDevice struct.
|
||||
/// @param device Pointer to the ASpiDevice struct.
|
||||
/// @param tx_data Buffer to write.
|
||||
/// @param rx_data Buffer to read data in. If NULL, no data will be read.
|
||||
/// @param len Length of the buffers.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BSpiDevice_transfer(const BSpiDevice* device,
|
||||
int ASpiDevice_transfer(const ASpiDevice* device,
|
||||
const void* tx_data,
|
||||
void* rx_data,
|
||||
size_t len);
|
||||
|
||||
/// Sets the frequency in Hertz.
|
||||
/// @param device Pointer to the BSpiDevice struct.
|
||||
/// @param device Pointer to the ASpiDevice struct.
|
||||
/// @param freq_hz Frequency to set.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BSpiDevice_setFrequency(const BSpiDevice* device, uint32_t freq_hz);
|
||||
int ASpiDevice_setFrequency(const ASpiDevice* device, uint32_t freq_hz);
|
||||
|
||||
/// Sets the SPI mode.
|
||||
/// @param device Pointer to the BSpiDevice struct.
|
||||
/// @param device Pointer to the ASpiDevice struct.
|
||||
/// @param mode Mode to use. One of SPI_MODE0, SPI_MODE1, SPI_MODE2, SPI_MODE3.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BSpiDevice_setMode(const BSpiDevice* device, int mode);
|
||||
int ASpiDevice_setMode(const ASpiDevice* device, ASpiMode mode);
|
||||
|
||||
/// Sets the bit justification.
|
||||
/// @param device Pointer to the BSpiDevice struct.
|
||||
/// @param device Pointer to the ASpiDevice struct.
|
||||
/// @param bit_justification One of SPI_LSB_FIRST OR SPI_MSB_FIRST.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BSpiDevice_setBitJustification(const BSpiDevice* device,
|
||||
int bit_justification);
|
||||
int ASpiDevice_setBitJustification(const ASpiDevice* device,
|
||||
ASpiBitJustification bit_justification);
|
||||
|
||||
/// Sets the number of bits per words.
|
||||
/// @param device Pointer to the BSpiDevice struct.
|
||||
/// @param device Pointer to the ASpiDevice struct.
|
||||
/// @param bits_per_word Number of bits per word.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BSpiDevice_setBitsPerWord(const BSpiDevice* device, uint8_t bits_per_word);
|
||||
int ASpiDevice_setBitsPerWord(const ASpiDevice* device, uint8_t bits_per_word);
|
||||
|
||||
/// Sets the delay to wait after each transfer.
|
||||
/// @param device Pointer to the BSpiDevice struct.
|
||||
/// @param device Pointer to the ASpiDevice struct.
|
||||
/// @param delay_usecs Delay in microseconds.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BSpiDevice_setDelay(const BSpiDevice* device, uint16_t delay_usecs);
|
||||
int ASpiDevice_setDelay(const ASpiDevice* device, uint16_t delay_usecs);
|
||||
|
||||
/// Sets the chip select behavior after each transfer.
|
||||
/// @param device Pointer to the BSpiDevice struct.
|
||||
/// @param device Pointer to the ASpiDevice struct.
|
||||
/// @param change If set, cs will be active between transfers.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BSpiDevice_setCsChange(const BSpiDevice* device, int change);
|
||||
int ASpiDevice_setCsChange(const ASpiDevice* device, int change);
|
||||
|
||||
/// Destroys a BSpiDevice struct.
|
||||
/// @param device Pointer to the BSpiDevice struct.
|
||||
void BSpiDevice_delete(BSpiDevice* device);
|
||||
/// Destroys a ASpiDevice struct.
|
||||
/// @param device Pointer to the ASpiDevice struct.
|
||||
void ASpiDevice_delete(ASpiDevice* device);
|
||||
|
||||
/// @}
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
@@ -31,133 +29,130 @@ __BEGIN_DECLS
|
||||
/// @{
|
||||
|
||||
/// UART Parity
|
||||
enum UartParity {
|
||||
UART_PARITY_NONE, /**< No parity */
|
||||
UART_PARITY_EVEN, /**< Even parity */
|
||||
UART_PARITY_ODD, /**< Odd parity */
|
||||
UART_PARITY_MARK, /**< Mark parity, always 1 */
|
||||
UART_PARITY_SPACE /**< Space parity, always 0 */
|
||||
};
|
||||
typedef enum AUartParity {
|
||||
AUART_PARITY_NONE = 0, /**< No parity */
|
||||
AUART_PARITY_EVEN = 1, /**< Even parity */
|
||||
AUART_PARITY_ODD = 2, /**< Odd parity */
|
||||
AUART_PARITY_MARK = 3, /**< Mark parity, always 1 */
|
||||
AUART_PARITY_SPACE = 4 /**< Space parity, always 0 */
|
||||
} AUartParity;
|
||||
|
||||
/// Modem control Bits
|
||||
enum UartModemControlBits {
|
||||
UART_MC_LE = TIOCM_LE, /**< Data set ready/Line enable */
|
||||
UART_MC_DTR = TIOCM_DTR, /**< Data terminal ready */
|
||||
UART_MC_RTS = TIOCM_RTS, /**< Request to send */
|
||||
UART_MC_ST = TIOCM_ST, /**< Secondary TXD */
|
||||
UART_MC_SR = TIOCM_SR, /**< Secondary RXD */
|
||||
UART_MC_CTS = TIOCM_CTS, /**< Clear to send */
|
||||
UART_MC_CD = TIOCM_CAR, /**< Data carrier detect */
|
||||
UART_MC_RI = TIOCM_RI, /**< Ring */
|
||||
UART_MC_DSR = TIOCM_DSR /**< Data set ready */
|
||||
};
|
||||
/// Modem control lines.
|
||||
typedef enum AUartModemControlLine {
|
||||
AUART_MODEM_CONTROL_LE = 1 << 0, /**< Data set ready/Line enable */
|
||||
AUART_MODEM_CONTROL_DTR = 1 << 1, /**< Data terminal ready */
|
||||
AUART_MODEM_CONTROL_RTS = 1 << 2, /**< Request to send */
|
||||
AUART_MODEM_CONTROL_ST = 1 << 3, /**< Secondary TXD */
|
||||
AUART_MODEM_CONTROL_SR = 1 << 4, /**< Secondary RXD */
|
||||
AUART_MODEM_CONTROL_CTS = 1 << 5, /**< Clear to send */
|
||||
AUART_MODEM_CONTROL_CD = 1 << 6, /**< Data carrier detect */
|
||||
AUART_MODEM_CONTROL_RI = 1 << 7, /**< Ring */
|
||||
AUART_MODEM_CONTROL_DSR = 1 << 8 /**< Data set ready */
|
||||
} AUartModemControlLine;
|
||||
|
||||
// Hardware Flow Control
|
||||
enum UartHardwareFlowControlType {
|
||||
UART_HW_FLOW_NONE, /**< No hardware flow control */
|
||||
UART_HW_FLOW_AUTO_RTSCTS /**< Auto RTS/CTS */
|
||||
};
|
||||
typedef enum AUartHardwareFlowControl {
|
||||
AUART_HARDWARE_FLOW_CONTROL_NONE = 0, /**< No hardware flow control */
|
||||
AUART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS = 1 /**< Auto RTS/CTS */
|
||||
} AUartHardwareFlowControl;
|
||||
|
||||
/// Flush queue selection
|
||||
enum UartFlushQueueSelection {
|
||||
UART_FLUSH_IN = TCIFLUSH, /**< Flushes data received but not read */
|
||||
UART_FLUSH_OUT = TCOFLUSH, /**< Flushes data written but not transmitted */
|
||||
UART_FLUSH_IN_OUT = TCIOFLUSH /**< Flushes both in and out */
|
||||
};
|
||||
typedef enum AUartFlushDirection {
|
||||
AUART_FLUSH_IN = 0, /**< Flushes data received but not read */
|
||||
AUART_FLUSH_OUT = 1, /**< Flushes data written but not transmitted */
|
||||
AUART_FLUSH_IN_OUT = 2 /**< Flushes both in and out */
|
||||
} AUartFlushDirection;
|
||||
|
||||
typedef struct BUartDevice BUartDevice;
|
||||
typedef struct AUartDevice AUartDevice;
|
||||
|
||||
/// Writes to a UART device.
|
||||
/// @param device Pointer to the BUartDevice struct.
|
||||
/// @param device Pointer to the AUartDevice struct.
|
||||
/// @param data Data to write.
|
||||
/// @param len Size of the data to write.
|
||||
/// @param bytes_written Output pointer to the number of bytes written.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BUartDevice_write(const BUartDevice* device,
|
||||
int AUartDevice_write(const AUartDevice* device,
|
||||
const void* data,
|
||||
uint32_t len,
|
||||
uint32_t* bytes_written);
|
||||
|
||||
/// Reads from a UART device.
|
||||
/// @param device Pointer to the BUartDevice struct.
|
||||
/// @param device Pointer to the AUartDevice struct.
|
||||
/// @param data Buffer to read the data into.
|
||||
/// @param len Number of bytes to read.
|
||||
/// @param bytes_read Output pointer to the number of bytes read.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BUartDevice_read(const BUartDevice* device,
|
||||
int AUartDevice_read(const AUartDevice* device,
|
||||
void* data,
|
||||
uint32_t len,
|
||||
uint32_t* bytes_read);
|
||||
|
||||
/// Sets the input and output speed of a UART device.
|
||||
/// @param device Pointer to the BUartDevice struct.
|
||||
/// @param device Pointer to the AUartDevice struct.
|
||||
/// @param baudrate Speed in baud.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BUartDevice_setBaudrate(const BUartDevice* device, uint32_t baudrate);
|
||||
int AUartDevice_setBaudrate(const AUartDevice* device, uint32_t baudrate);
|
||||
|
||||
/// Sets number of stop bits for the UART device.
|
||||
/// @param device Pointer to the BUartDevice struct.
|
||||
/// @param device Pointer to the AUartDevice struct.
|
||||
/// @param stop_bits Number of stop bits. Typically 1 or 2.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BUartDevice_setStopBits(const BUartDevice* device, uint32_t stop_bits);
|
||||
int AUartDevice_setStopBits(const AUartDevice* device, uint32_t stop_bits);
|
||||
|
||||
/// Sets the data size of a character for the UART device.
|
||||
/// @param device Pointer to the BUartDevice struct.
|
||||
/// @param device Pointer to the AUartDevice struct.
|
||||
/// @param data_size Number of bits per character. Typically between 5 and 8.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BUartDevice_setDataSize(const BUartDevice* device, uint32_t data_size);
|
||||
int AUartDevice_setDataSize(const AUartDevice* device, uint32_t data_size);
|
||||
|
||||
/// Sets the parity mode for the UART device.
|
||||
/// @param device Pointer to the BUartDevice struct.
|
||||
/// @param mode Parity mode. One of UART_PARITY_NONE, UART_PARITY_EVEN,
|
||||
/// UART_PARITY_ODD, UART_PARITY_MARK, UART_PARITY_SPACE.
|
||||
/// @param device Pointer to the AUartDevice struct.
|
||||
/// @param mode Parity mode.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BUartDevice_setParity(const BUartDevice* device, uint32_t mode);
|
||||
int AUartDevice_setParity(const AUartDevice* device, AUartParity mode);
|
||||
|
||||
/// Sets the hardware flow control mode for the UART device.
|
||||
/// @param device Pointer to the BUartDevice struct.
|
||||
/// @param mode Flow control mode. Either UART_HW_FLOW_NONE or
|
||||
/// UART_HW_FLOW_AUTO_RTSCTS.
|
||||
/// @param device Pointer to the AUartDevice struct.
|
||||
/// @param mode Flow control mode.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BUartDevice_setHardwareFlowControl(const BUartDevice* device,
|
||||
uint32_t mode);
|
||||
int AUartDevice_setHardwareFlowControl(const AUartDevice* device,
|
||||
AUartHardwareFlowControl mode);
|
||||
|
||||
/// Sets the modem control bits for the UART device.
|
||||
/// @param device Pointer to the BUartDevice struct.
|
||||
/// @param bits Modem control bits to set.
|
||||
/// @param device Pointer to the AUartDevice struct.
|
||||
/// @param lines Lines to set. AUartModemControlLine values OR'ed together.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BUartDevice_setModemControl(const BUartDevice* device, uint32_t bits);
|
||||
int AUartDevice_setModemControl(const AUartDevice* device, uint32_t lines);
|
||||
|
||||
/// Clears the modem control bits for the UART device.
|
||||
/// @param device Pointer to the BUartDevice struct.
|
||||
/// @param bits Modem control bits to clear.
|
||||
/// @param device Pointer to the AUartDevice struct.
|
||||
/// @param lines Lines to clear. AUartModemControlLine values OR'ed together.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BUartDevice_clearModemControl(const BUartDevice* device, uint32_t bits);
|
||||
int AUartDevice_clearModemControl(const AUartDevice* device, uint32_t lines);
|
||||
|
||||
/// Sends a break to the UART device.
|
||||
/// @param device Pointer to the BUartDevice struct.
|
||||
/// @param device Pointer to the AUartDevice struct.
|
||||
/// @param duration Duration of break transmission in milliseconds. If 0,
|
||||
/// transmits zero-valued bits for at least 0.25 seconds, and not more
|
||||
/// than 0.5 seconds.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BUartDevice_sendBreak(const BUartDevice* device, uint32_t duration_msecs);
|
||||
int AUartDevice_sendBreak(const AUartDevice* device, uint32_t duration_msecs);
|
||||
|
||||
/// Flushes specified queue for the UART device.
|
||||
/// @param device Pointer to the BUartDevice struct.
|
||||
/// @param queue Queue to flush. One of UART_FLUSH_IN, UART_FLUSH_OUT,
|
||||
/// UART_FLUSH_IN_OUT.
|
||||
/// @param device Pointer to the AUartDevice struct.
|
||||
/// @param direction Direction to flush.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BUartDevice_flush(const BUartDevice* device, uint32_t queue);
|
||||
int AUartDevice_flush(const AUartDevice* device, AUartFlushDirection direction);
|
||||
|
||||
/// Gets a file descriptor to be notified when data can be read.
|
||||
///
|
||||
/// You can use this file descriptor to poll on incoming data instead of
|
||||
/// actively reading for new data.
|
||||
///
|
||||
/// @param device Pointer to the BUartDevice struct.
|
||||
/// @param device Pointer to the AUartDevice struct.
|
||||
/// @param fd Output pointer to the file descriptor.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BUartDevice_getPollingFd(const BUartDevice* device, int* fd);
|
||||
int AUartDevice_getPollingFd(const AUartDevice* device, int* fd);
|
||||
|
||||
/// Acknowledges an input event.
|
||||
///
|
||||
@@ -170,11 +165,11 @@ int BUartDevice_getPollingFd(const BUartDevice* device, int* fd);
|
||||
///
|
||||
/// @param fd File descriptor to acknowledge the event on.
|
||||
/// @return 0 on success, errno on error.
|
||||
int BUartDevice_ackInputEvent(int fd);
|
||||
int AUartDevice_ackInputEvent(int fd);
|
||||
|
||||
/// Destroys a BUartDevice struct.
|
||||
/// @param device Pointer to the BUartDevice struct.
|
||||
void BUartDevice_delete(BUartDevice* device);
|
||||
/// Destroys a AUartDevice struct.
|
||||
/// @param device Pointer to the AUartDevice struct.
|
||||
void AUartDevice_delete(AUartDevice* device);
|
||||
|
||||
/// @}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "mraa_internal.h"
|
||||
#include "peripheralman.h"
|
||||
|
||||
BPeripheralManagerClient *client = NULL;
|
||||
APeripheralManagerClient *client = NULL;
|
||||
char **gpios = NULL;
|
||||
int gpios_count = 0;
|
||||
char **i2c_busses = NULL;
|
||||
@@ -42,8 +42,8 @@ int uart_busses_count = 0;
|
||||
static mraa_result_t
|
||||
mraa_pman_uart_init_raw_replace(mraa_uart_context dev, const char* path)
|
||||
{
|
||||
if (BPeripheralManagerClient_openUartDevice(client, path, &dev->buart) != 0) {
|
||||
BUartDevice_delete(dev->buart);
|
||||
if (APeripheralManagerClient_openUartDevice(client, path, &dev->buart) != 0) {
|
||||
AUartDevice_delete(dev->buart);
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ mraa_pman_uart_set_baudrate_replace(mraa_uart_context dev, unsigned int baud)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (BUartDevice_setBaudrate(dev->buart, baud) != 0) {
|
||||
if (AUartDevice_setBaudrate(dev->buart, baud) != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ mraa_pman_uart_read_replace(mraa_uart_context dev, char* buf, size_t len)
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
rc = BUartDevice_read(dev->buart, buf, len, &bytes_read);
|
||||
rc = AUartDevice_read(dev->buart, buf, len, &bytes_read);
|
||||
if (rc != 0) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
@@ -99,7 +99,7 @@ mraa_pman_uart_write_replace(mraa_uart_context dev, const char* buf, size_t len)
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
rc = BUartDevice_write(dev->buart, buf, len, &bytes_written);
|
||||
rc = AUartDevice_write(dev->buart, buf, len, &bytes_written);
|
||||
if (rc != 0) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
@@ -142,7 +142,7 @@ static mraa_result_t
|
||||
mraa_pman_spi_init_raw_replace(mraa_spi_context dev, unsigned int bus, unsigned int cs)
|
||||
{
|
||||
int rc;
|
||||
rc = BPeripheralManagerClient_openSpiDevice(client, spi_busses[bus], &dev->bspi);
|
||||
rc = APeripheralManagerClient_openSpiDevice(client, spi_busses[bus], &dev->bspi);
|
||||
if (rc != 0) {
|
||||
free(dev);
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
@@ -162,19 +162,19 @@ mraa_pman_spi_mode_replace(mraa_spi_context dev, mraa_spi_mode_t mode)
|
||||
|
||||
switch (mode) {
|
||||
case MRAA_SPI_MODE0:
|
||||
rc = BSpiDevice_setMode(dev->bspi, SPI_MODE0);
|
||||
rc = ASpiDevice_setMode(dev->bspi, ASPI_MODE0);
|
||||
break;
|
||||
case MRAA_SPI_MODE1:
|
||||
rc = BSpiDevice_setMode(dev->bspi, SPI_MODE1);
|
||||
rc = ASpiDevice_setMode(dev->bspi, ASPI_MODE1);
|
||||
break;
|
||||
case MRAA_SPI_MODE2:
|
||||
rc = BSpiDevice_setMode(dev->bspi, SPI_MODE2);
|
||||
rc = ASpiDevice_setMode(dev->bspi, ASPI_MODE2);
|
||||
break;
|
||||
case MRAA_SPI_MODE3:
|
||||
rc = BSpiDevice_setMode(dev->bspi, SPI_MODE3);
|
||||
rc = ASpiDevice_setMode(dev->bspi, ASPI_MODE3);
|
||||
break;
|
||||
default:
|
||||
rc = BSpiDevice_setMode(dev->bspi, SPI_MODE0);
|
||||
rc = ASpiDevice_setMode(dev->bspi, ASPI_MODE0);
|
||||
break;
|
||||
}
|
||||
if (rc != 0) {
|
||||
@@ -195,7 +195,7 @@ mraa_pman_spi_frequency_replace(mraa_spi_context dev, int hz)
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
rc = BSpiDevice_setFrequency(dev->bspi, hz);
|
||||
rc = ASpiDevice_setFrequency(dev->bspi, hz);
|
||||
if (rc != 0) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
@@ -215,9 +215,9 @@ mraa_pman_spi_lsbmode_replace(mraa_spi_context dev, mraa_boolean_t lsb)
|
||||
}
|
||||
|
||||
if (lsb) {
|
||||
rc = BSpiDevice_setBitJustification(dev->bspi, SPI_LSB_FIRST);
|
||||
rc = ASpiDevice_setBitJustification(dev->bspi, ASPI_LSB_FIRST);
|
||||
} else {
|
||||
rc = BSpiDevice_setBitJustification(dev->bspi, SPI_MSB_FIRST);
|
||||
rc = ASpiDevice_setBitJustification(dev->bspi, ASPI_MSB_FIRST);
|
||||
}
|
||||
if (rc != 0) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
@@ -234,7 +234,7 @@ mraa_pman_spi_bit_per_word_replace(mraa_spi_context dev, unsigned int bits)
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
if (BSpiDevice_setBitsPerWord(dev->bspi, bits) != 0) {
|
||||
if (ASpiDevice_setBitsPerWord(dev->bspi, bits) != 0) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ mraa_pman_spi_write_replace(mraa_spi_context dev, uint8_t data)
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = BSpiDevice_transfer(dev->bspi, &data, &recv, 1);
|
||||
rc = ASpiDevice_transfer(dev->bspi, &data, &recv, 1);
|
||||
if (rc != 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -269,7 +269,7 @@ mraa_pman_spi_write_word_replace(mraa_spi_context dev, uint16_t data)
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = BSpiDevice_transfer(dev->bspi, &data, &recv, 2);
|
||||
rc = ASpiDevice_transfer(dev->bspi, &data, &recv, 2);
|
||||
if (rc != 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -286,7 +286,7 @@ mraa_pman_spi_transfer_buf_replace(mraa_spi_context dev, uint8_t* data, uint8_t*
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
rc = BSpiDevice_transfer(dev->bspi, data, rxbuf, length);
|
||||
rc = ASpiDevice_transfer(dev->bspi, data, rxbuf, length);
|
||||
if (rc != 0) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
@@ -304,7 +304,7 @@ mraa_pman_spi_transfer_buf_word_replace(mraa_spi_context dev, uint16_t* data, ui
|
||||
}
|
||||
|
||||
// IS IT CORRECT ?
|
||||
rc = BSpiDevice_transfer(dev->bspi, data, rxbuf, length * 2);
|
||||
rc = ASpiDevice_transfer(dev->bspi, data, rxbuf, length * 2);
|
||||
if (rc != 0) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
@@ -316,7 +316,7 @@ static mraa_result_t
|
||||
mraa_pman_spi_stop_replace(mraa_spi_context dev)
|
||||
{
|
||||
if (dev->bspi != NULL) {
|
||||
BSpiDevice_delete(dev->bspi);
|
||||
ASpiDevice_delete(dev->bspi);
|
||||
dev->bspi = NULL;
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ static mraa_result_t
|
||||
mraa_pman_i2c_stop_replace(mraa_i2c_context dev)
|
||||
{
|
||||
if (dev->bi2c != NULL) {
|
||||
BI2cDevice_delete(dev->bi2c);
|
||||
AI2cDevice_delete(dev->bi2c);
|
||||
dev->bi2c = NULL;
|
||||
}
|
||||
|
||||
@@ -361,10 +361,10 @@ mraa_pman_i2c_address_replace(mraa_i2c_context dev, uint8_t addr)
|
||||
dev->addr = (int) addr;
|
||||
|
||||
if (strlen(dev->bus_name) > 0) {
|
||||
rc = BPeripheralManagerClient_openI2cDevice(client,
|
||||
rc = APeripheralManagerClient_openI2cDevice(client,
|
||||
dev->bus_name, addr, &dev->bi2c);
|
||||
} else {
|
||||
rc = BPeripheralManagerClient_openI2cDevice(client,
|
||||
rc = APeripheralManagerClient_openI2cDevice(client,
|
||||
i2c_busses[dev->busnum], addr, &dev->bi2c);
|
||||
}
|
||||
if (rc != 0) {
|
||||
@@ -383,7 +383,7 @@ mraa_pman_i2c_read_replace(mraa_i2c_context dev, uint8_t* data, int length)
|
||||
return 0;
|
||||
}
|
||||
|
||||
rc = BI2cDevice_read(dev->bi2c, data, length);
|
||||
rc = AI2cDevice_read(dev->bi2c, data, length);
|
||||
|
||||
return rc;
|
||||
}
|
||||
@@ -398,7 +398,7 @@ mraa_pman_i2c_read_byte_replace(mraa_i2c_context dev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
rc = BI2cDevice_read(dev->bi2c, &val, 1);
|
||||
rc = AI2cDevice_read(dev->bi2c, &val, 1);
|
||||
if (rc != 0 ) {
|
||||
return rc;
|
||||
}
|
||||
@@ -416,7 +416,7 @@ mraa_pman_i2c_read_byte_data_replace(mraa_i2c_context dev, uint8_t command)
|
||||
return 0;
|
||||
}
|
||||
|
||||
rc = BI2cDevice_readRegByte(dev->bi2c, command, &val);
|
||||
rc = AI2cDevice_readRegByte(dev->bi2c, command, &val);
|
||||
if (rc != 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -433,7 +433,7 @@ mraa_pman_i2c_read_bytes_data_replace(mraa_i2c_context dev, uint8_t command, uin
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = BI2cDevice_readRegBuffer(dev->bi2c, command, data, length);
|
||||
rc = AI2cDevice_readRegBuffer(dev->bi2c, command, data, length);
|
||||
|
||||
return rc;
|
||||
}
|
||||
@@ -448,7 +448,7 @@ mraa_pman_i2c_read_word_data_replace(mraa_i2c_context dev, uint8_t command)
|
||||
return 0;
|
||||
}
|
||||
|
||||
rc = BI2cDevice_readRegWord(dev->bi2c, command, &val);
|
||||
rc = AI2cDevice_readRegWord(dev->bi2c, command, &val);
|
||||
if (rc != 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -465,7 +465,7 @@ mraa_pman_i2c_write_replace(mraa_i2c_context dev, const uint8_t* data, int lengt
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
rc = BI2cDevice_write(dev->bi2c, data, length);
|
||||
rc = AI2cDevice_write(dev->bi2c, data, length);
|
||||
if (rc != 0) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
@@ -488,7 +488,7 @@ mraa_pman_i2c_write_byte_data_replace(mraa_i2c_context dev, const uint8_t data,
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
rc = BI2cDevice_writeRegByte(dev->bi2c, command, data);
|
||||
rc = AI2cDevice_writeRegByte(dev->bi2c, command, data);
|
||||
if (rc != 0) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
@@ -505,7 +505,7 @@ mraa_pman_i2c_write_word_data_replace(mraa_i2c_context dev, const uint16_t data,
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
rc = BI2cDevice_writeRegWord(dev->bi2c, command, data);
|
||||
rc = AI2cDevice_writeRegWord(dev->bi2c, command, data);
|
||||
if (rc != 0) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
@@ -516,7 +516,7 @@ mraa_pman_i2c_write_word_data_replace(mraa_i2c_context dev, const uint16_t data,
|
||||
static mraa_result_t
|
||||
mraa_pman_gpio_init_internal_replace(mraa_gpio_context dev, int pin)
|
||||
{
|
||||
int rc = BPeripheralManagerClient_openGpio(client, gpios[pin], &dev->bgpio);
|
||||
int rc = APeripheralManagerClient_openGpio(client, gpios[pin], &dev->bgpio);
|
||||
if (rc != 0) {
|
||||
syslog(LOG_ERR, "peripheralmanager: Failed to init gpio");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
@@ -531,7 +531,7 @@ static mraa_result_t
|
||||
mraa_pman_gpio_close_replace(mraa_gpio_context dev)
|
||||
{
|
||||
if (dev->bgpio != NULL) {
|
||||
BGpio_delete(dev->bgpio);
|
||||
AGpio_delete(dev->bgpio);
|
||||
}
|
||||
|
||||
free(dev);
|
||||
@@ -550,14 +550,14 @@ mraa_pman_gpio_dir_replace(mraa_gpio_context dev, mraa_gpio_dir_t dir)
|
||||
|
||||
switch (dir) {
|
||||
case MRAA_GPIO_IN:
|
||||
rc = BGpio_setDirection(dev->bgpio, DIRECTION_IN);
|
||||
rc = AGpio_setDirection(dev->bgpio, AGPIO_DIRECTION_IN);
|
||||
break;
|
||||
case MRAA_GPIO_OUT:
|
||||
case MRAA_GPIO_OUT_HIGH:
|
||||
rc = BGpio_setDirection(dev->bgpio, DIRECTION_OUT_INITIALLY_HIGH);
|
||||
rc = AGpio_setDirection(dev->bgpio, AGPIO_DIRECTION_OUT_INITIALLY_HIGH);
|
||||
break;
|
||||
case MRAA_GPIO_OUT_LOW:
|
||||
rc = BGpio_setDirection(dev->bgpio, DIRECTION_OUT_INITIALLY_LOW);
|
||||
rc = AGpio_setDirection(dev->bgpio, AGPIO_DIRECTION_OUT_INITIALLY_LOW);
|
||||
break;
|
||||
}
|
||||
if (rc != 0) {
|
||||
@@ -585,7 +585,7 @@ mraa_pman_gpio_write_replace(mraa_gpio_context dev, int val)
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
rc = BGpio_setValue(dev->bgpio, val);
|
||||
rc = AGpio_setValue(dev->bgpio, val);
|
||||
if (rc != 0) {
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
@@ -603,7 +603,7 @@ mraa_pman_gpio_read_replace(mraa_gpio_context dev)
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = BGpio_getValue(dev->bgpio, &val);
|
||||
rc = AGpio_getValue(dev->bgpio, &val);
|
||||
if (rc != 0) {
|
||||
syslog(LOG_ERR, "peripheralman: Unable to read internal gpio");
|
||||
return -1;
|
||||
@@ -623,16 +623,16 @@ mraa_pman_gpio_edge_mode_replace(mraa_gpio_context dev, mraa_gpio_edge_t mode)
|
||||
|
||||
switch (mode) {
|
||||
case MRAA_GPIO_EDGE_BOTH:
|
||||
rc = BGpio_setEdgeTriggerType(dev->bgpio, BOTH_EDGE);
|
||||
rc = AGpio_setEdgeTriggerType(dev->bgpio, AGPIO_EDGE_BOTH);
|
||||
break;
|
||||
case MRAA_GPIO_EDGE_FALLING:
|
||||
rc = BGpio_setEdgeTriggerType(dev->bgpio, FALLING_EDGE);
|
||||
rc = AGpio_setEdgeTriggerType(dev->bgpio, AGPIO_EDGE_FALLING);
|
||||
break;
|
||||
case MRAA_GPIO_EDGE_RISING:
|
||||
rc = BGpio_setEdgeTriggerType(dev->bgpio, RISING_EDGE);
|
||||
rc = AGpio_setEdgeTriggerType(dev->bgpio, AGPIO_EDGE_RISING);
|
||||
break;
|
||||
case MRAA_GPIO_EDGE_NONE:
|
||||
rc = BGpio_setEdgeTriggerType(dev->bgpio, NONE_EDGE);
|
||||
rc = AGpio_setEdgeTriggerType(dev->bgpio, AGPIO_EDGE_NONE);
|
||||
break;
|
||||
}
|
||||
if (rc != 0) {
|
||||
@@ -663,19 +663,19 @@ mraa_peripheralman_plat_init()
|
||||
}
|
||||
|
||||
if (client != NULL) {
|
||||
BPeripheralManagerClient_delete(client);
|
||||
APeripheralManagerClient_delete(client);
|
||||
}
|
||||
|
||||
client = BPeripheralManagerClient_new();
|
||||
client = APeripheralManagerClient_new();
|
||||
if (client == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// error checking?
|
||||
gpios = BPeripheralManagerClient_listGpio(client, &gpios_count);
|
||||
i2c_busses = BPeripheralManagerClient_listI2cBuses(client, &i2c_busses_count);
|
||||
spi_busses = BPeripheralManagerClient_listSpiBuses(client, &spi_busses_count);
|
||||
uart_devices = BPeripheralManagerClient_listUartDevices(client, &uart_busses_count);
|
||||
gpios = APeripheralManagerClient_listGpio(client, &gpios_count);
|
||||
i2c_busses = APeripheralManagerClient_listI2cBuses(client, &i2c_busses_count);
|
||||
spi_busses = APeripheralManagerClient_listSpiBuses(client, &spi_busses_count);
|
||||
uart_devices = APeripheralManagerClient_listUartDevices(client, &uart_busses_count);
|
||||
|
||||
b->platform_name = "peripheralmanager";
|
||||
// query this from peripheral manager?
|
||||
@@ -704,16 +704,9 @@ mraa_peripheralman_plat_init()
|
||||
for (; i < gpios_count; i++) {
|
||||
b->pins[i].name = gpios[i];
|
||||
b->pins[i].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
|
||||
b->pins[i].gpio.pinmap = i;
|
||||
b->pins[i].gpio.pinmap = -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < i2c_busses_count; i++) {
|
||||
b->i2c_bus[i].bus_id = i;
|
||||
b->i2c_bus[i].sda = -1;
|
||||
b->i2c_bus[i].scl = -1;
|
||||
}
|
||||
|
||||
|
||||
b->adv_func = (mraa_adv_func_t*) calloc(1, sizeof(mraa_adv_func_t));
|
||||
if (b->adv_func == NULL) {
|
||||
free(b->pins);
|
||||
@@ -802,7 +795,7 @@ pman_mraa_deinit()
|
||||
free_resources(&gpios, gpios_count);
|
||||
|
||||
if (client != NULL) {
|
||||
BPeripheralManagerClient_delete(client);
|
||||
APeripheralManagerClient_delete(client);
|
||||
client = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user