https://github.com/zenitheesc/platform-lib
https://github.com/zenitheesc/platform-lib
arduino arduino-ide c cplusplus cube-ide embedded-systems esp32 platformio stm32
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/zenitheesc/platform-lib
- Owner: zenitheesc
- License: mit
- Created: 2025-02-10T18:58:47.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-02-25T23:57:07.000Z (11 months ago)
- Last Synced: 2025-02-26T00:27:08.787Z (11 months ago)
- Topics: arduino, arduino-ide, c, cplusplus, cube-ide, embedded-systems, esp32, platformio, stm32
- Language: C
- Homepage:
- Size: 63.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Platform Lib
The project was created to refactor and finish the lib platform, which was begun for the old members of Zenith to enable some drivers (utilizing the lib) for embedded systems with different microcontrollers.
# Platform.h
## Objective
Platform headers is an abstraction layer to help application drivers to be
platform agnostic. That means that including the header will provide a
common interface between our embedded platforms such as STM32 (HAL) or
Arduino.
## Scope
Each platform implementation provides access to common (internal) peripherals,
such as I2C, SPI, UART and ADCs. As it's expected to be implemented in various
circumstances, the scope is limited to transmitting and receiving raw bytes.
## Usage
E
Just add the `platform/` folder to the project, then
`#include "platform.h"` in the driver. It then checks for
preprocessor macros to detect which platform is being compiled.
For STM32, it will also attempt to find the proper chip family HAL.
If a platform is not found it is assumed to be running on a PC.
This means calls will be logged to `stdout` with no side-effects.
## Notes
If you're using an arduino (or esp-idf) implementation, put the `#include "platform/platform.h" after
includes to other arduino (or esp-idf) libraries.
## To do
Finish that tasks later
* CAN protocol functions in Platform:
- [ ] arduinoIDE
- [ ] STM32 (cubeIDE)
* Interrupts use functions:
- [ ] arduinoIDE
- [ ] STM32 (cubeIDE)
* DMA use functions:
- [ ] arduinoIDE
- [ ] STM32 (cubeIDE)
* Implementation of Platform-Lib for ESP32 using expressifeIDE
## Specification
Common •
GPIO •
I2C •
SPI •
UART •
ADC •
PWM
### Common
#### Types
- `error_t`
```c
typedef int error_t;
```
This is a common error code type, it is recommended to be an underlying `int` but can also be a platform specific. The requirement is that
evaluation of no error is false. So essentially, that the following pattern
still applies:
```c
if(error){
// error handling...
}
// ... code assuming no errors
```
This pattern was chosen to prevent [Indent Hadouken](https://i.pinimg.com/originals/98/bd/38/98bd38321fad0e8b14ebf3a5a9ec70c9.jpg)
- `buffer_view_t`
```c
typedef struct {
uint8_t *data;
int size;
} buffer_view_t;
```
It's used to pass pointers to `data` buffers of `size`. It is used throughout
this header to pass a bunch of bytes. This was chosen to keep things simple
and prevent mixing up sizes and arrays.
- `result{8,16,float}_t`
```c
typedef struct {
error_t hasError;
uint8_t value;
} result8_t;
```
The `results` are a complement to the error handling strategy. Because
there are no parameters in C, the platform header only creates result types
for common types: `uint8_t`, `uint16_t` and `float`. Other result types
should be declared on a driver-by-driver basis.
#### Functions
- `delay_ms`
```c
void delay_ms(uint32_t time);
```
A blocking millisecond delay. It is recommended that RTOS use be
detected via preprocessor macros, so that drivers can take advantage.
### GPIO
#### Types
- `gpio_pin_t`
```c
typedef struct {
*port;
uint16_t pin;
} gpio_pin_t;
```
GPIO Pin Type
- `gpio_state_t`
```C
typedef enum{
gpio_low_level = 0U,
gpio_high_level
} gpio_state_t
```
GPIO state type
#### Functions
- `gpio_read`
```c
gpio_state_t gpio_read(gpio_pin_t pin);
```
- `gpio_low`
```c
void gpio_low(gpio_pin_t pin);
```
Reset GPIO
- `gpio_high`
```c
void gpio_high(gpio_pin_t pin);
```
Set GPIO
- `gpio_toggle`
```c
void gpio_toggle(gpio_pin_t pin);
```
Toggle GPIO
### I2C
#### Types
- `i2c_t`
```c
typedef i2c_dev_t;
```
I2C Interface Type
- `i2c_dev_t`
```c
typedef struct {
i2c_t *i2c;
uint8_t address;
} i2c_device_t;
```
I2C Device Type
#### Functions
- `i2c_transmit`
```c
error_t i2c_transmit(i2c_device_t device, buffer_view_t buffer);
```
Transmit bytes via I2C
- `i2c_receive`
```c
error_t i2c_receive(i2c_device_t device, buffer_view_t buffer);
```
Receive bytes via I2C
### SPI
#### Types
- `spi_t`
```c
typedef spi_t;
```
SPI Interface Type
- `spi_dev_t`
```c
typedef struct {
spi_t *spi;
gpio_pin_t pin;
} spi_device_t;
```
SPI Device Type
#### Functions
- `spi_transceive`
```c
error_t spi_transceive(spi_device_t device, buffer_view_t rx_buffer,
buffer_view_t tx_buffer);
```
Transceive (Transmit and Receive) via SPI
- `spi_transmit`
```c
error_t spi_transmit(spi_device_t device, buffer_view_t tx_buffer);
```
Transmit via SPI
- `spi_transceive`
```c
error_t spi_receive(spi_device_t device, buffer_view_t rx_buffer);
```
Receive via SPI
### UART
#### Types
- `uart_t`
```c
typedef uart_t;
```
UART Interface Type
- `uart_connection_t`
```c
typedef struct {
uart_t *uart;
} uart_connection_t;
```
UART Connection Type
#### Functions
- `uart_init`
```c
void uart_init(uart_connection_t conn, uint32_t baudRate, uint32_t timeOut);
```
- `uart_transmit`
```c
error_t uart_transmit(uart_connection_t conn, buffer_view_t buffer);
```
Transmit bytes via UART
- `uart_receive`
```c
error_t uart_receive(uart_connection_t conn, buffer_view_t buffer);
```
Receive bytes via UART
### ADC
#### Types
- `adc_handle_t`
```c
typedef adc_handle_t;
```
ADC Channel Type
- `adc_t`
```c
typedef struct {
adc_handle_t handle;
uint8_t bits;
float voltage_reference;
} adc_t;
```
ADC Type
#### Functions
- `adc_init`
```c
error_t adc_init(adc_t *adc);
```
ADC initialization
- `adc_read`
```c
result_uint16_t adc_read(adc_t *adc);
```
ADC Read raw value
- `adc_raw_to_voltage`
```c
float adc_raw_to_voltage(const adc_t *adc, const uint16_t value);
```
ADC conversion to volts.
### PWM
#### Types
- `pwm_handle_t`
```c
typedef pwm_handle_t;
```
PWM Handle Type
- `pwm_channel_t`
```c
typedef pwm_channel_t;
```
PWM Channel Type
- `pwm_t`
```c
typedef struct {
pwm_handle_t handle;
pwm_channel_t channel;
uint8_t bits;
} pwm_t;
```
PWM Type
#### Functions
- `pwm_start`
```C
error_t pwm_start(pwm_t pwm)
```
PWM start conection
- `pwm_write`
```c
error_t pwm_write(pwm_t pwm)
```
PWM module signal