fc10ef2e10
GD32F470ZGT6 based project with full peripheral support: - SDRAM (W9825G6KH) via EXMC - LCD NT35510 (480x800) via EXMC NOR/PSRAM - Flash (W25Q64) via SPI - UART (USART0) debug console - LED indicators - CMSIS-DAP debug interface - CMake + ARM GCC toolchain build system
67 lines
2.1 KiB
C
67 lines
2.1 KiB
C
#ifndef __C_API_H__
|
|
#define __C_API_H__
|
|
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* ========== GPIO C API ========== */
|
|
#define GPIO_MODE_INPUT 0
|
|
#define GPIO_MODE_OUTPUT 1
|
|
#define GPIO_MODE_AF 2
|
|
#define GPIO_MODE_ANALOG 3
|
|
|
|
#define GPIO_PUPD_NONE 0
|
|
#define GPIO_PUPD_PULLUP 1
|
|
#define GPIO_PUPD_PULLDOWN 2
|
|
|
|
#define GPIO_PORT_A 0
|
|
#define GPIO_PORT_B 1
|
|
#define GPIO_PORT_C 2
|
|
#define GPIO_PORT_D 3
|
|
#define GPIO_PORT_E 4
|
|
#define GPIO_PORT_F 5
|
|
#define GPIO_PORT_G 6
|
|
#define GPIO_PORT_H 7
|
|
#define GPIO_PORT_I 8
|
|
|
|
int gpio_init(uint8_t port, uint32_t pin, uint8_t mode, uint8_t pupd);
|
|
int gpio_set(uint8_t port, uint32_t pin);
|
|
int gpio_reset(uint8_t port, uint32_t pin);
|
|
int gpio_toggle(uint8_t port, uint32_t pin);
|
|
uint8_t gpio_read(uint8_t port, uint32_t pin);
|
|
|
|
/* ========== UART C API ========== */
|
|
int uart_init(uint8_t port, uint32_t baudrate);
|
|
int uart_send_byte(uint8_t port, uint8_t data);
|
|
int uart_send_data(uint8_t port, const uint8_t *data, uint32_t len);
|
|
int uart_receive_byte(uint8_t port, uint8_t *data, uint32_t timeout_ms);
|
|
|
|
/* ========== I2C C API ========== */
|
|
int i2c_init(uint8_t port, uint32_t speed_hz);
|
|
int i2c_master_write(uint8_t port, uint16_t dev_addr, const uint8_t *data, uint32_t len);
|
|
int i2c_master_read(uint8_t port, uint16_t dev_addr, uint8_t *data, uint32_t len);
|
|
int i2c_master_write_read(uint8_t port, uint16_t dev_addr, const uint8_t *wdata, uint32_t wlen, uint8_t *rdata, uint32_t rlen);
|
|
|
|
/* ========== SPI C API ========== */
|
|
int spi_bus_init(uint8_t port, uint32_t speed_hz, uint8_t mode);
|
|
int spi_transfer(uint8_t port, uint32_t cs_port, uint32_t cs_pin, const uint8_t *tx, uint8_t *rx, uint32_t len);
|
|
|
|
/* ========== ADC C API ========== */
|
|
int adc_init(uint8_t port, uint32_t resolution);
|
|
uint16_t adc_read(uint8_t port, uint8_t channel);
|
|
float adc_read_voltage(uint8_t port, uint8_t channel);
|
|
|
|
/* ========== Timer C API ========== */
|
|
int timer_bus_init(uint8_t port, uint32_t prescaler, uint32_t period);
|
|
int timer_start(uint8_t port);
|
|
int timer_stop(uint8_t port);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* __C_API_H__ */
|