SDK API 使用指南
优质
小牛编辑
131浏览
2023-12-01
API接口按模块划分。如下图:
涉及的模块有:
- GPIO
- I2C
- SPI
- PWM
- 声音输入
- 声音输出和播放
- UART
下面给出开发常用的api参考接口,其它模块具体的可以到对应driver下去查询。
GPIO
参考代码在:vsp\mcu\drivers\gpio\gpio_nre.c
typedef enum {
GPIO_DIRECTION_INPUT = 0,
GPIO_DIRECTION_OUTPUT
} GPIO_DIRECTION;
GPIO_DIRECTION GpioGetDirection(unsigned int port);
int GpioSetDirection(unsigned int port, GPIO_DIRECTION direction);
typedef enum {
GPIO_LEVEL_LOW = 0,
GPIO_LEVEL_HIGH
} GPIO_LEVEL;
GPIO_LEVEL GpioGetLevel(unsigned int port);
int GpioSetLevel(unsigned int port, GPIO_LEVEL level);
//-------------------------------------------------------------------------------------------------
// GPIO trigger function
typedef enum {
GPIO_TRIGGER_EDGE_FALLING = 0x01,
GPIO_TRIGGER_EDGE_RISING = 0x02,
GPIO_TRIGGER_EDGE_BOTH = 0x03,
GPIO_TRIGGER_LEVEL_HIGH = 0x04,
GPIO_TRIGGER_LEVEL_LOW = 0x08,
} GPIO_TRIGGER_EDGE;
typedef int (*GPIO_CALLBACK)(unsigned int port, void *pdata);
void GpioMaskTrigger(unsigned int port);
void GpioUnmaskTrigger(unsigned int port);
int GpioEnableTrigger(unsigned int port, GPIO_TRIGGER_EDGE edge, GPIO_CALLBACK callback, void *pdata);
int GpioDisableTrigger(unsigned int port);
void GpioSuspend(void);
void GpioResume(void);
PWM
参考代码在:vsp\mcu\drivers\gpio\gpio_nre.c
// GPIO PWM function
int GpioEnablePWM(unsigned int port, unsigned int freq, unsigned int duty);
int GpioDisablePWM(unsigned int port);
I2C
参考代码在:vsp\mcu\drivers\i2c\drv_dw_i2c.c
/* i2c master*/
void *gx_i2c_open(unsigned int id);
int gx_i2c_set_speed(unsigned int id, unsigned int speed);
int gx_i2c_transfer(void *dev, struct i2c_msg *msgs, int num);
int gx_i2c_tx(int bus_id, unsigned int devid, unsigned int reg_address, unsigned char *tx_data, unsigned int count);
int gx_i2c_rx(int bus_id, unsigned int devid, unsigned int reg_address, unsigned char *rx_data, unsigned int count);
int gx_i2c_close(void *dev);
/* i2c slave*/
void *gx_i2c_slave_open(unsigned int id, unsigned int devid, i2c_slave_cb_t callback);
int gx_i2c_slave_close(void *dev);
SPI
参考代码在:vsp\mcu\drivers\spi\dw_spi.c
int spi_device_init(struct spi_device* spi_device);
int spi_xfer(const struct spi_device* spi_device, const uint8_t *tx, uint8_t *rx, uint32_t len);
int spi_write_then_read(const struct spi_device* spi_device,
const uint8_t *txbuf, unsigned int n_tx,
void *rxbuf, unsigned int n_rx);
UART
参考代码在:vsp\mcu\drivers\uart\dw_uart.c
支持同步读写和异步读写
我们实现了套串口交互协议,称为:uart message 2.0 协议。参考:vsp\mcu\vsp\common\uart_message_v2.c