Test program done

This commit is contained in:
Luca Lizaranzu
2026-03-20 11:41:44 -07:00
parent 303a554595
commit 1b29371fff
20 changed files with 1037 additions and 114 deletions

View File

@@ -18,44 +18,46 @@ SHAL_GPIO::SHAL_GPIO(GPIO_Key key) : m_GPIO_KEY(key) {
SHAL_apply_bitmask(GPIORCCEnable.reg,GPIORCCEnable.mask);
}
void SHAL_GPIO::setLow() {
void SHAL_GPIO::setLow() const {
auto outputDataReg = getGPIOOutputDataRegister(m_GPIO_KEY);
SHAL_set_bits(outputDataReg.reg,1,0,outputDataReg.offset);
}
void SHAL_GPIO::setHigh() {
void SHAL_GPIO::setHigh() const {
auto outputDataReg = getGPIOOutputDataRegister(m_GPIO_KEY);
SHAL_set_bits(outputDataReg.reg,1,1,outputDataReg.offset);
}
void SHAL_GPIO::toggle() volatile {
void SHAL_GPIO::toggle() const volatile {
auto outputDataReg = getGPIOOutputDataRegister(m_GPIO_KEY);
SHAL_flip_bits(outputDataReg.reg,1,outputDataReg.offset);
}
void SHAL_GPIO::setOutputType(PinType type) volatile {
void SHAL_GPIO::setOutputType(PinType type) const volatile {
auto outputTypeReg = getGPIOOutputTypeRegister(m_GPIO_KEY);
SHAL_set_bits(outputTypeReg.reg,2,static_cast<uint8_t>(type),outputTypeReg.offset);
}
void SHAL_GPIO::setOutputSpeed(OutputSpeed speed) volatile {
void SHAL_GPIO::setOutputSpeed(OutputSpeed speed) const volatile {
auto outputSpeedReg = getGPIOOutputSpeedRegister(m_GPIO_KEY);
SHAL_set_bits(outputSpeedReg.reg,2,static_cast<uint8_t>(speed),outputSpeedReg.offset);
}
void SHAL_GPIO::setInternalResistor(InternalResistorType type) volatile {
void SHAL_GPIO::setInternalResistor(InternalResistorType type) const volatile {
auto pupdreg = getGPIOPUPDRegister(m_GPIO_KEY);
SHAL_set_bits(pupdreg.reg,2,static_cast<uint8_t>(type),pupdreg.offset);
}
void SHAL_GPIO::setAlternateFunction(GPIO_Alternate_Function AF) volatile {
void SHAL_GPIO::setAlternateFunction(GPIO_Alternate_Function AF) const volatile {
auto alternateFunctionReg = getGPIOAlternateFunctionRegister(m_GPIO_KEY);
SHAL_set_bits(alternateFunctionReg.reg,4,static_cast<uint8_t>(AF),alternateFunctionReg.offset);
}
SHAL_Result SHAL_GPIO::setPinMode(PinMode mode) volatile {
SHAL_Result SHAL_GPIO::setPinMode(PinMode mode) const volatile {
auto pinModeReg = getGPIOModeRegister(m_GPIO_KEY);
GPIOManager::initGPIO(m_GPIO_KEY);
/*
if(mode == PinMode::ANALOG_MODE && getGPIOPortInfo(m_GPIO_KEY).ADCChannel == SHAL_ADC_Channel::NO_ADC_MAPPING){
char buff[100];
@@ -69,6 +71,12 @@ SHAL_Result SHAL_GPIO::setPinMode(PinMode mode) volatile {
return SHAL_Result::OKAY;
}
uint16_t SHAL_GPIO::digitalRead() const {
auto offset = getGPIOPinNumber(m_GPIO_KEY);
return (SHAL_check_bit(getGPIOInputDataRegister(m_GPIO_KEY).reg, 1 << offset)) ? 1 : 0;
}
/* TODO Fix implementation for STM32F072
void SHAL_GPIO::useAsExternalInterrupt(TriggerMode mode, EXTICallback callback) {
@@ -116,10 +124,20 @@ uint16_t SHAL_GPIO::analogRead(SHAL_ADC_SampleTime sampleTime) {
SHAL_ADC_Channel channel = getGPIOPortInfo(m_GPIO_KEY).ADCChannel;
return GPIOManager::getGPIOADC().singleConvertSingle(channel,sampleTime);
return GPIOManager::getGPIOADC().singleConvertSingle(channel,sampleTime);
}
*/
SHAL_GPIO& GPIOManager::get(GPIO_Key key) {
SHAL_GPIO& GPIOManager::get(const uint8_t portNum, const uint8_t pinNum) {
uint8_t pinIndex = (PINS_PER_PORT * portNum) + pinNum;
initGPIO(static_cast<GPIO_Key>(pinIndex));
return m_gpios[portNum][pinNum];
}
void GPIOManager::initGPIO(GPIO_Key key) {
unsigned int gpioPort = getGPIOPortNumber(key);
uint8_t gpioPin = getGPIOPinNumber(key);
@@ -127,6 +145,12 @@ SHAL_GPIO& GPIOManager::get(GPIO_Key key) {
if (m_gpios[gpioPort][gpioPin].m_GPIO_KEY == GPIO_Key::INVALID){
m_gpios[gpioPort][gpioPin] = SHAL_GPIO(key);
}
return m_gpios[gpioPort][gpioPin];
}
SHAL_GPIO& GPIOManager::get(const GPIO_Key key) {
initGPIO(key);
return m_gpios[getGPIOPortNumber(key)][getGPIOPinNumber(key)];
}