Beginnings of I2C object functions
This commit is contained in:
@@ -40,7 +40,7 @@ constexpr SHAL_I2C_Pair getI2CPair(const I2C_Pair pair){
|
|||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr SHAL_I2C_Enable_REG getI2CEnableReg(const I2C_Pair pair){
|
constexpr SHAL_I2C_Enable_Reg getI2CEnableReg(const I2C_Pair pair){
|
||||||
switch(pair){
|
switch(pair){
|
||||||
case I2C_Pair::SCL1B6_SDA1B7:
|
case I2C_Pair::SCL1B6_SDA1B7:
|
||||||
case I2C_Pair::SCL1B8_SDA1B9:
|
case I2C_Pair::SCL1B8_SDA1B9:
|
||||||
@@ -56,4 +56,37 @@ constexpr SHAL_I2C_Enable_REG getI2CEnableReg(const I2C_Pair pair){
|
|||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr SHAL_I2C_Reset_Reg getI2CResetReg(const I2C_Pair pair){
|
||||||
|
switch(pair){
|
||||||
|
case I2C_Pair::SCL1B6_SDA1B7:
|
||||||
|
case I2C_Pair::SCL1B8_SDA1B9:
|
||||||
|
return {&RCC->APB1RSTR,RCC_APB1RSTR_I2C1RST};
|
||||||
|
case I2C_Pair::SCL2B10_SDA2B11:
|
||||||
|
case I2C_Pair::SCL2B13_SDA2B14:
|
||||||
|
return {&RCC->APB1RSTR,RCC_APB1RSTR_I2C2RST};
|
||||||
|
case I2C_Pair::NUM_PAIRS:
|
||||||
|
case I2C_Pair::INVALID:
|
||||||
|
assert(false);
|
||||||
|
return {nullptr, 0};
|
||||||
|
}
|
||||||
|
__builtin_unreachable();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Gets all the bits in the I2C timer register, these values should rarely be manually set, but I wanted to support it anyway
|
||||||
|
constexpr SHAL_I2C_Timing_Reg getI2CTimerReg(const I2C_Pair pair){
|
||||||
|
switch(pair){
|
||||||
|
case I2C_Pair::SCL1B6_SDA1B7:
|
||||||
|
case I2C_Pair::SCL1B8_SDA1B9:
|
||||||
|
return {&I2C1->TIMINGR,31,4,23,4,19,4,15,8,7,0};
|
||||||
|
case I2C_Pair::SCL2B10_SDA2B11:
|
||||||
|
case I2C_Pair::SCL2B13_SDA2B14:
|
||||||
|
return {&I2C2->TIMINGR,31,4,23,4,19,4,15,8,7,0};
|
||||||
|
case I2C_Pair::NUM_PAIRS:
|
||||||
|
case I2C_Pair::INVALID:
|
||||||
|
assert(false);
|
||||||
|
__builtin_unreachable();
|
||||||
|
}
|
||||||
|
__builtin_unreachable();
|
||||||
|
}
|
||||||
|
|
||||||
#endif //SHAL_I2C_REG_F072XB_H
|
#endif //SHAL_I2C_REG_F072XB_H
|
||||||
|
|||||||
@@ -17,9 +17,29 @@ struct SHAL_I2C_Pair {
|
|||||||
GPIO_Alternate_Function SDA_Mask;
|
GPIO_Alternate_Function SDA_Mask;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SHAL_I2C_Enable_REG{
|
struct SHAL_I2C_Enable_Reg{
|
||||||
volatile uint32_t* reg;
|
volatile uint32_t* reg;
|
||||||
uint32_t mask;
|
uint32_t mask;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SHAL_I2C_Reset_Reg{
|
||||||
|
volatile uint32_t* reg;
|
||||||
|
uint32_t mask;
|
||||||
|
};
|
||||||
|
|
||||||
|
//Manual values for I2C timer register
|
||||||
|
struct SHAL_I2C_Timing_Reg{
|
||||||
|
volatile uint32_t* reg;
|
||||||
|
uint8_t prescaler_offset;
|
||||||
|
uint8_t prescaler_width;
|
||||||
|
uint8_t dataSetupTime_offset;
|
||||||
|
uint8_t dataSetupTime_width;
|
||||||
|
uint8_t dataHoldTime_offset;
|
||||||
|
uint8_t dataHoldTime_width;
|
||||||
|
uint8_t SCLHighPeriod_offset;
|
||||||
|
uint8_t SCLHighPeriod_width;
|
||||||
|
uint8_t SCLLowPeriod_offset;
|
||||||
|
uint8_t SCLLowPeriod_width;
|
||||||
|
};
|
||||||
|
|
||||||
#endif //SHMINGO_HAL_SHAL_I2C_TYPES_H
|
#endif //SHMINGO_HAL_SHAL_I2C_TYPES_H
|
||||||
|
|||||||
@@ -15,6 +15,16 @@ class SHAL_I2C{
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
void init(I2C_Pair pair) volatile;
|
||||||
|
|
||||||
|
void masterTransmit();
|
||||||
|
|
||||||
|
//Manually set the clock configuration. Refer to your MCU's reference manual for examples
|
||||||
|
void setClockConfig(uint8_t prescaler, uint8_t dataSetupTime, uint8_t dataHoldTime, uint8_t SCLHighPeriod, uint8_t SCLLowPeriod);
|
||||||
|
|
||||||
|
//Set clock configuration based on a value calculated from STM32CubeMX, or other similar tools
|
||||||
|
void setClockConfig(uint32_t configuration);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
SHAL_I2C() = default;
|
SHAL_I2C() = default;
|
||||||
|
|||||||
@@ -2,3 +2,9 @@
|
|||||||
// Created by Luca on 9/9/2025.
|
// Created by Luca on 9/9/2025.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include "SHAL_I2C.h"
|
||||||
|
|
||||||
|
void SHAL_I2C::init() volatile {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user