| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- /*
- * This file is an interface file for I2C communication between MCU (Controller) and other peripherals (Target): i2c_hal.c
- * Context:
- * Our current functions in ADC and DAC are tightly coupled with I2C communication.
- * Need a communication mechanism to isolate the flow of the ADC function from Asynchronous calls.
- * Decision:
- * i2c_controller_interface is a header file which defines what the I2C peripheral does:
- * - i2c READ
- * - i2c WRITE
- * - i2c start controller transfer
- * - i2c enable interrupt
- * - i2c bus wait
- * Consequences:
- * Cleaner platform independent file
- Reference:
- - https://www.embeddedrelated.com/showarticle/1596.php
- - https://www.beningo.com/5-tips-for-designing-an-interface-in-c/
- - https://iot.sites.arm.com/open-iot-sdk/libraries/mcu-driver-hal/mcu-driver-hal/pwmout__api_8h_source.html
- */
- #ifndef I2C_INTERFACE_H_
- #define I2C_INTERFACE_H_
- #include <stdint.h>
- #include <stdbool.h>
- //Maximum packet sizes
- #define I2C_TX_MAX_PACKET_SIZE (4)
- #define I2C_RX_MAX_PACKET_SIZE (4)
- typedef struct {
- volatile bool complete;
- uint8_t packet[I2C_RX_MAX_PACKET_SIZE];
- uint8_t count;
- uint8_t len;
- } I2CRxPackage;
- extern I2CRxPackage controllerRxPackage;
- typedef struct {
- volatile bool complete;
- uint8_t packet[I2C_TX_MAX_PACKET_SIZE];
- uint8_t count;
- uint8_t len;
- } I2CTxPackage;
- extern I2CTxPackage controllerTxPackage;
- /*
- * Since C does not allows to add functions in typedef struct, however a function pointer can be included in Structure in C. This interface provides a standard features of i2c_hal
- */
- typedef struct{
- bool (*write)(uint8_t const TARGET_ADDRESS);
- bool (*read) (uint8_t const TARGET_ADDRESS);
- } I2C_Interface;
- extern I2C_Interface i2c_hal;
- #endif
|