Hardware interface API

Hardware interface related API.

Module pins

Module I/O pin definitions.

enumModulePinDef

ValuesDescriptions
PIN_BANDread-only
PIN_ADC1
PIN_ADC0
PIN_PULSE1
PIN_PULSE0
PIN_UART0_RTS
PIN_GPIO2
PIN_GPIO3
PIN_RF_ENread-only
PIN_SPI_CS
PIN_SPI_SCK
PIN_SPI_MISO
PIN_SPI_MOSI
PIN_GPIO0_WKUP
PIN_RF_TEST2reserved
PIN_GPIO4
PIN_GPIO5
PIN_GPIO6
PIN_GPIO1_WKUP
PIN_UART1_RX
PIN_UART1_TX
PIN_I2C_SCL
PIN_I2C_SDA
PIN_GPIO8
PIN_GPIO7
PIN_UART0_CTS
PIN_UART0_TX
PIN_UART0_RX
PIN_LEUART_RX
PIN_LEUART_TX
PIN_MAX

Module pin definitions.

ADC

PinNum can be PIN_ADC0 or PIN_ADC1.

enumADCReference

ValuesDescriptions
ADC_REF_VIOuse VIO_REF as reference voltage
ADC_REF_2V5use 2.5V as reference voltage
ADC_REF_1V25use 1.25V as reference voltage

Reference voltages.

intADCGetVoltage(uint8_t PinNum,ADCReferenceReference,uint32_t * mV)

Get the converted voltage (mV) from the MCU ADC port.

Returns 0 if read succeeds and -1 if read fails.

intADCGetValue(uint8_t PinNum,ADCReferenceReference,uint16_t * Value)

Get raw value from the ADC port (0 - 0xFFF).

Returns 0 if read succeeds and -1 if read fails.

I2C master

intI2CInit(void)

Initialise I2C bus.

Returns 0 if initialisation succeeds and -1 if initialisation fails.

voidI2CDeinit(void)

Deinitialise I2C bus.

intI2CWrite(uint16_t DeviceAddress,const uint8_t * Command,size_t CommandLength)

Write to an I2C device synchronously.

Returns 0 if write succeeds and -1 if read fails.

intI2CRead(uint16_t DeviceAddress,const uint8_t * Command,size_t CommandLength,uint8_t * Rx,size_t RxLength)

Read from an I2C device.

Returns 0 if read succeeds and -1 if read fails.

SPI master

enumSPIBaudrate

ValuesDescriptions
SPI_BAUDRATE_DEFAULTdefault SPI baudrate
SPI_BAUDRATE_MAXmaximum SPI baudrate

SPI baudrate.

intSPIInit(uint32_t BaudRate)

Initialise SPI master.

Returns 0 if initialisation succeeds and -1 if initialisation fails.

voidSPIDeinit(void)

Deinitialise SPI master.

intSPIWrite(const uint8_t * Tx,size_t Length)

Write to an SPI device synchronously.

Returns 0 if write succeeds and -1 if write fails.

intSPITransfer(const uint8_t * Tx,uint8_t * Rx,size_t Length)

SPI data transfer.

Returns 0 if transfer succeeds and -1 if transfer fails.

GPIO

PinNum can be any pin in ModulePinDef.

enumGPIOLevel

ValuesDescriptions
GPIO_LOW
GPIO_HIGH

GPIO level.

enumGPIOPull

ValuesDescriptions
GPIO_NO_PULLno module internal pull up or pull down
GPIO_PULL_UPmodule internal pull up
GPIO_PULL_DOWNmodule internal pull down

GPIO internal pull up/down.

intGPIOSetModeInput(uint8_t PinNum,GPIOPullPull)

Set a GPIO to input mode and the internal pull up/down.

Returns 0 if succeeded and -1 if failed.

intGPIOSetModeOutput(uint8_t PinNum)

Set a GPIO to output mode.

Returns 0 if succeeded and -1 if failed.

intGPIOSetHigh(uint8_t PinNum)

Set a GPIO output high.

Returns 0 if succeeded and -1 if failed.

intGPIOSetLow(uint8_t PinNum)

Set a GPIO output low.

Returns 0 if succeeded and -1 if failed.

intGPIOGet(uint8_t PinNum)

Get input level of a GPIO.

Returns GPIOLevel if succeeded and -1 if failed.

intGPIOSetWakeupLevel(uint8_t PinNum,GPIOLevelLevel)

Set level polarity of a GPIO pin with wakeup capability for next wakeup.

Make sure to set the GPIO to input mode. Returns 0 if succeeded and -1 if failed.

intGPIODisableWakeup(uint8_t PinNum)

Disable wakeup capability of a GPIO pin.

UART

enumUARTInterface

ValuesDescriptions
UART_0can be used for firmware update via the bootloader
UART_1used by GNSS
LEUARTlow energy, only supports baudrate up to 9600

UART interfaces.

void *UARTInit(UARTInterfaceUARTNum,uint32_t BaudRate,uint32_t Options)

Initialise a uart interface, options are not supported and should be 0.

UARTNum is the UART number defined by enum UARTInterface. Returns the handle if succeeded and NULL if failed.

voidUARTDeinit(void * Handle)

Deintialise a UART interface.

intUARTWrite(void * Handle,const uint8_t * Tx,size_t Length)

Write to a UART interface synchronously.

Returns 0 if write succeeds and -1 if read fails.

intUARTRead(void * Handle,uint8_t * Rx,size_t Length)

Read from input buffer of a UART interface.

Returns number of bytes read back and -1 if read fails.

Pulse counter

enumPulseCounterOption

ValuesDescriptions
PCNT_EDGE_FALLINGcount on falling edge, default rising edge
PCNT_DEBOUNCE_DISABLEdisable hardware debouncing, default enabled for about 160us

Pulse counter bit-wise options, can be ORed.

intPulseCounterInit(uint32_t Limit,uint32_t Options)

Initialise the pulse counter and configure the event generation logic.

Event is generated when pulse count hits multiple of Limit. Limit can be set to 0 to 256, or multiple of 256. Set Limit to 0 to disable event generation. Options are used to configure the pulse counter. Set option to 0 to count on rising edge, and enable debouncing. Returns 0 if succeeded and -1 if failed.

uint64_tPulseCounterGet(void)

Get the total count of the pulse counter.

Returns the total count.

voidPulseCounterDeinit(void)

Deinitialise the pulse counter.