Finish testing stage
This commit is contained in:
@@ -178,7 +178,7 @@ getTimerCaptureCompareModeRegistersOutput(Timer_Key key) {
|
|||||||
|
|
||||||
static inline SHAL_TIM_Break_Dead_Time_Register getTimerBreakDeadTimeRegister(Timer_Key key){
|
static inline SHAL_TIM_Break_Dead_Time_Register getTimerBreakDeadTimeRegister(Timer_Key key){
|
||||||
|
|
||||||
SHAL_TIM_Break_Dead_Time_Register res = {nullptr, 1UL << 15};
|
SHAL_TIM_Break_Dead_Time_Register res = {nullptr, TIM_BDTR_MOE};
|
||||||
|
|
||||||
volatile TIM_TypeDef* tim = TIM_TABLE[static_cast<uint8_t>(key)];
|
volatile TIM_TypeDef* tim = TIM_TABLE[static_cast<uint8_t>(key)];
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ void Timer::init(uint32_t prescaler, uint32_t autoReload) {
|
|||||||
|
|
||||||
setPrescaler(prescaler);
|
setPrescaler(prescaler);
|
||||||
setARR(autoReload);
|
setARR(autoReload);
|
||||||
|
|
||||||
|
*getTimerStatusRegister(m_key).reg = 0;
|
||||||
|
*getTimerDMAInterruptEnableRegister(m_key).reg = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timer::setPWMMode(SHAL_Timer_Channel channel, SHAL_TIM_Output_Compare_Mode outputCompareMode, SHAL_Timer_Channel_Main_Output_Mode mainOutputMode,
|
void Timer::setPWMMode(SHAL_Timer_Channel channel, SHAL_TIM_Output_Compare_Mode outputCompareMode, SHAL_Timer_Channel_Main_Output_Mode mainOutputMode,
|
||||||
@@ -89,6 +92,7 @@ void Timer::setPWMMode(SHAL_Timer_Channel channel, SHAL_TIM_Output_Compare_Mode
|
|||||||
|
|
||||||
SHAL_set_bits(ccer.reg, 4, fullChannelModeMask, offset);
|
SHAL_set_bits(ccer.reg, 4, fullChannelModeMask, offset);
|
||||||
SHAL_apply_bitmask(bdtr.reg, bdtr.main_output_enable_mask);
|
SHAL_apply_bitmask(bdtr.reg, bdtr.main_output_enable_mask);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timer::setPWMDutyCycle(uint32_t dutyCycle) {
|
void Timer::setPWMDutyCycle(uint32_t dutyCycle) {
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ DEFINE_TIMER_IRQ(Timer_Key::S_TIM1, TIM1_IRQHandler)
|
|||||||
DEFINE_TIMER_IRQ(Timer_Key::S_TIM2, TIM2_IRQHandler)
|
DEFINE_TIMER_IRQ(Timer_Key::S_TIM2, TIM2_IRQHandler)
|
||||||
DEFINE_TIMER_IRQ(Timer_Key::S_TIM6, TIM6_IRQHandler)
|
DEFINE_TIMER_IRQ(Timer_Key::S_TIM6, TIM6_IRQHandler)
|
||||||
DEFINE_TIMER_IRQ(Timer_Key::S_TIM7, TIM7_IRQHandler)
|
DEFINE_TIMER_IRQ(Timer_Key::S_TIM7, TIM7_IRQHandler)
|
||||||
DEFINE_TIMER_IRQ(Timer_Key::S_TIM15, TIM15_IRQHandler)
|
DEFINE_TIMER_IRQ(Timer_Key::S_TIM15, TIM1_BRK_TIM15_IRQHandler)
|
||||||
DEFINE_TIMER_IRQ(Timer_Key::S_TIM16, TIM16_IRQHandler)
|
DEFINE_TIMER_IRQ(Timer_Key::S_TIM16, TIM1_UP_TIM16_IRQHandler)
|
||||||
|
|
||||||
void registerTimerCallback(Timer_Key key, TimerCallback callback){
|
void registerTimerCallback(Timer_Key key, TimerCallback callback){
|
||||||
timer_callbacks[static_cast<uint32_t>(key)] = callback;
|
timer_callbacks[static_cast<uint32_t>(key)] = callback;
|
||||||
|
|||||||
@@ -19,13 +19,14 @@ uint16_t vals[NUM_CHANNELS] = {0,0,0,0,0,0,0,0};
|
|||||||
uint8_t currentSensor = 0;
|
uint8_t currentSensor = 0;
|
||||||
|
|
||||||
bool isAlarmBeeping = false;
|
bool isAlarmBeeping = false;
|
||||||
bool prevIsCalibrateButtonHigh = false;
|
|
||||||
|
|
||||||
uint16_t sensorThresholds[NUM_CHANNELS] = {};
|
uint16_t sensorThresholds[NUM_CHANNELS];
|
||||||
|
|
||||||
int buzzer_beepCount = 0;
|
int buzzer_beepCount = 0;
|
||||||
bool isBeepingForCalibration = false;
|
bool isBeepingForCalibration = false;
|
||||||
|
|
||||||
|
bool prevIsCalibrateButtonHigh = false;
|
||||||
|
|
||||||
int cyclesPerPrint = 2;
|
int cyclesPerPrint = 2;
|
||||||
int currentCycle = 0;
|
int currentCycle = 0;
|
||||||
|
|
||||||
@@ -44,10 +45,12 @@ void getSensorData(){
|
|||||||
|
|
||||||
currentSensor = (currentSensor + 1) % NUM_CHANNELS;
|
currentSensor = (currentSensor + 1) % NUM_CHANNELS;
|
||||||
currentCycle = (currentCycle + 1) % cyclesPerPrint;
|
currentCycle = (currentCycle + 1) % cyclesPerPrint;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void startBeeping(){
|
void startBeeping(){
|
||||||
SHAL_TIM1.start();
|
SHAL_TIM6.init(4000000,400); //PWM switcher - standard error beeping rate
|
||||||
|
|
||||||
SHAL_TIM6.start();
|
SHAL_TIM6.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +61,50 @@ void stopBeeping(){
|
|||||||
isBeepingForCalibration = false;
|
isBeepingForCalibration = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void checkSensorThresholds(){
|
||||||
|
|
||||||
|
//bool sensorsRequirementsTemp = areSensorRequirementsMetCurrent; TODO uncomment all of this
|
||||||
|
|
||||||
|
/*
|
||||||
|
for(int i = 0; i < NUM_CHANNELS; i++){
|
||||||
|
if(vals[i] < sensorThresholds[i]){
|
||||||
|
areSensorRequirementsMetCurrent = false; //All sensors must be valid
|
||||||
|
|
||||||
|
if(sensorsRequirementsTemp){ //Requirements were met before and aren't now, so start beeping timer
|
||||||
|
SHAL_TIM15.start();
|
||||||
|
PIN(B5).setHigh();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(areSensorRequirementsMetCurrent){
|
||||||
|
SHAL_TIM15.stop();
|
||||||
|
stopBeeping();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Copied from loop TODO remove this once real functionality is implemented
|
||||||
|
if(!areSensorRequirementsMetCurrent){
|
||||||
|
|
||||||
|
if(areSensorRequirementsMetPrevious) {
|
||||||
|
PIN(B5).setHigh();
|
||||||
|
SHAL_TIM15.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
else{
|
||||||
|
PIN(B5).setLow();
|
||||||
|
|
||||||
|
if(!areSensorRequirementsMetPrevious) { //Transition from not met -> met
|
||||||
|
SHAL_TIM15.stop();
|
||||||
|
stopBeeping();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void calibrateThresholds(){
|
void calibrateThresholds(){
|
||||||
|
|
||||||
for(int i = 0; i < 6; i++){
|
for(int i = 0; i < 6; i++){
|
||||||
@@ -66,9 +113,13 @@ void calibrateThresholds(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PWMToggle(){
|
void PWMToggle(){
|
||||||
|
|
||||||
|
//Flash light
|
||||||
|
PIN(B5).toggle();
|
||||||
|
|
||||||
|
SHAL_TIM15.stop(); //Stop timer for allowed time off sensors
|
||||||
|
|
||||||
if(isBeepingForCalibration && buzzer_beepCount > 2){
|
if(isBeepingForCalibration && buzzer_beepCount > 2){
|
||||||
isBeepingForCalibration = false;
|
isBeepingForCalibration = false;
|
||||||
buzzer_beepCount = 0;
|
buzzer_beepCount = 0;
|
||||||
@@ -88,7 +139,8 @@ void PWMToggle(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void buttonHoldCallback(){
|
void buttonHoldCallback(){
|
||||||
PIN(B3).toggle();
|
|
||||||
|
PIN(B5).toggle();
|
||||||
|
|
||||||
SHAL_TIM7.stop(); //Stop this timer
|
SHAL_TIM7.stop(); //Stop this timer
|
||||||
|
|
||||||
@@ -110,18 +162,21 @@ int main() {
|
|||||||
|
|
||||||
SHAL_init();
|
SHAL_init();
|
||||||
|
|
||||||
//SHAL_UART2.init(UART_Pair_Key::Tx2A2_Rx2A3);
|
SHAL_UART2.init(UART_Pair_Key::Tx2A2_Rx2A3);
|
||||||
//SHAL_UART2.begin(115200);
|
SHAL_UART2.begin(115200);
|
||||||
|
|
||||||
PIN(A0).setPinMode(PinMode::ANALOG_MODE);
|
PIN(A0).setPinMode(PinMode::ANALOG_MODE);
|
||||||
PIN(A1).setPinMode(PinMode::ANALOG_MODE);
|
PIN(A1).setPinMode(PinMode::ANALOG_MODE);
|
||||||
PIN(A2).setPinMode(PinMode::ANALOG_MODE);
|
//PIN(A2).setPinMode(PinMode::ANALOG_MODE);
|
||||||
PIN(A3).setPinMode(PinMode::ANALOG_MODE);
|
//PIN(A3).setPinMode(PinMode::ANALOG_MODE);
|
||||||
PIN(A4).setPinMode(PinMode::ANALOG_MODE);
|
PIN(A4).setPinMode(PinMode::ANALOG_MODE);
|
||||||
PIN(A5).setPinMode(PinMode::ANALOG_MODE);
|
PIN(A5).setPinMode(PinMode::ANALOG_MODE);
|
||||||
PIN(A6).setPinMode(PinMode::ANALOG_MODE);
|
PIN(A6).setPinMode(PinMode::ANALOG_MODE);
|
||||||
PIN(A7).setPinMode(PinMode::ANALOG_MODE);
|
PIN(A7).setPinMode(PinMode::ANALOG_MODE);
|
||||||
|
|
||||||
|
PIN(B5).setPinMode(PinMode::OUTPUT_MODE);
|
||||||
|
|
||||||
|
PIN(B6).setPinMode(PinMode::INPUT_MODE);
|
||||||
|
|
||||||
SHAL_TIM2.init(4000000,400);
|
SHAL_TIM2.init(4000000,400);
|
||||||
|
|
||||||
@@ -131,12 +186,11 @@ int main() {
|
|||||||
|
|
||||||
PIN(B0).setAlternateFunction(GPIO_Alternate_Function_Mapping::B0_TIM1CH2N);
|
PIN(B0).setAlternateFunction(GPIO_Alternate_Function_Mapping::B0_TIM1CH2N);
|
||||||
|
|
||||||
SHAL_TIM1.init(0,2400);
|
SHAL_TIM1.init(0,2400); //PWM signal
|
||||||
SHAL_TIM1.setPWMMode(SHAL_Timer_Channel::CH2,SHAL_TIM_Output_Compare_Mode::PWMMode1,SHAL_Timer_Channel_Main_Output_Mode::Disabled,SHAL_Timer_Channel_Complimentary_Output_Mode::Polarity_Reversed);
|
SHAL_TIM1.setPWMMode(SHAL_Timer_Channel::CH2,SHAL_TIM_Output_Compare_Mode::PWMMode1,SHAL_Timer_Channel_Main_Output_Mode::Polarity_Normal,SHAL_Timer_Channel_Complimentary_Output_Mode::Polarity_Reversed);
|
||||||
SHAL_TIM1.setPWMDutyCycle(900);
|
SHAL_TIM1.setPWMDutyCycle(900);
|
||||||
//PIN(B0).setPinMode(PinMode::OUTPUT_MODE);
|
|
||||||
|
|
||||||
SHAL_TIM6.init(4000000,400);
|
SHAL_TIM6.init(4000000,400); //PWM switcher
|
||||||
SHAL_TIM6.setCallbackFunc(PWMToggle);
|
SHAL_TIM6.setCallbackFunc(PWMToggle);
|
||||||
SHAL_TIM6.enableInterrupt();
|
SHAL_TIM6.enableInterrupt();
|
||||||
|
|
||||||
@@ -144,31 +198,25 @@ int main() {
|
|||||||
SHAL_TIM7.setCallbackFunc(buttonHoldCallback);
|
SHAL_TIM7.setCallbackFunc(buttonHoldCallback);
|
||||||
SHAL_TIM7.enableInterrupt();
|
SHAL_TIM7.enableInterrupt();
|
||||||
|
|
||||||
PIN(B6).setPinMode(PinMode::INPUT_MODE);
|
SHAL_TIM15.init(4000000,5000); //1 second
|
||||||
PIN(B3).setPinMode(PinMode::OUTPUT_MODE); //Test
|
SHAL_TIM15.setCallbackFunc(startBeeping);
|
||||||
PIN(B3).setLow();
|
SHAL_TIM15.enableInterrupt();
|
||||||
|
|
||||||
while (true) {
|
|
||||||
//Retarded polling based button methods cause EXTI decided to not work on L432KC for some stupid reason at the last second
|
|
||||||
if(!(PIN(B6).digitalRead() == 1)){
|
|
||||||
areSensorRequirementsMetCurrent = true;
|
|
||||||
|
|
||||||
if(!areSensorRequirementsMetPrevious){
|
while (true) { //TODO set to use button for simulating off sensor, uncomment for real functionality
|
||||||
startBeeping();
|
|
||||||
}
|
if(PIN(B6).digitalRead() != 1){
|
||||||
|
areSensorRequirementsMetCurrent = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if(!prevIsCalibrateButtonHigh){
|
if(!prevIsCalibrateButtonHigh){
|
||||||
SHAL_TIM7.start();
|
SHAL_TIM7.start();
|
||||||
}
|
}
|
||||||
prevIsCalibrateButtonHigh = true;
|
prevIsCalibrateButtonHigh = true;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
areSensorRequirementsMetCurrent = false;
|
areSensorRequirementsMetCurrent = true;
|
||||||
if(areSensorRequirementsMetPrevious){
|
|
||||||
stopBeeping();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if(prevIsCalibrateButtonHigh){
|
if(prevIsCalibrateButtonHigh){
|
||||||
@@ -176,9 +224,12 @@ int main() {
|
|||||||
SHAL_TIM7.stop();
|
SHAL_TIM7.stop();
|
||||||
}
|
}
|
||||||
prevIsCalibrateButtonHigh = false;
|
prevIsCalibrateButtonHigh = false;
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkSensorThresholds();
|
||||||
|
|
||||||
areSensorRequirementsMetPrevious = areSensorRequirementsMetCurrent;
|
areSensorRequirementsMetPrevious = areSensorRequirementsMetCurrent;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user