add beeper to socket_fans

This commit is contained in:
eddyem 2020-10-27 00:14:41 +03:00
parent 325898bc52
commit 4f3332737f
4 changed files with 103 additions and 2 deletions

View File

@ -23,8 +23,9 @@
#include "adc.h"
#include "hardware.h"
#include "proto.h"
uint8_t ledsON = 0;
buzzer_state buzzer = BUZZER_OFF; // buzzer state
void adc_setup(){
uint16_t ctr = 0; // 0xfff0 - more than 1.3ms
@ -187,6 +188,62 @@ void Jump2Boot(){
SysMemBootJump();
}
void buzzer_chk(){ // check buzzer state
static uint32_t lastTms = 0;
static buzzer_state oldstate = BUZZER_OFF;
uint32_t B, S; // length of beep and silence
if(buzzer == oldstate){ // keep current state
if(lastTms > Tms) return;
switch(buzzer){ // beep on/off
case BUZZER_LONG:
B = LONG_BUZZER_PERIOD;
S = LONG_BUZZER_PAUSE;
SEND("long ");
break;
case BUZZER_SHORT:
B = SHORT_BUZZER_PERIOD;
S = SHORT_BUZZER_PAUSE;
SEND("short ");
break;
default:
return;
}
if(CHK(BUZZER)){ // is ON
SEND("1->0\n");
OFF(BUZZER);
lastTms = Tms + S;
}else{ // is OFF
SEND("0->1\n");
ON(BUZZER);
lastTms = Tms + B;
}
sendbuf();
return;
}
SEND("New state: ");
switch(buzzer){ // change buzzer state
case BUZZER_ON:
ON(BUZZER);
SEND("on");
break;
case BUZZER_OFF:
OFF(BUZZER);
SEND("off");
break;
case BUZZER_LONG:
ON(BUZZER);
lastTms = Tms + LONG_BUZZER_PERIOD;
SEND("long");
break;
case BUZZER_SHORT:
ON(BUZZER);
lastTms = Tms + SHORT_BUZZER_PERIOD;
SEND("short");
break;
}
newline(); sendbuf();
oldstate = buzzer;
}
void exti4_15_isr(){
EXTI->PR |= EXTI_PR_PR7; // clear pending bit

View File

@ -61,16 +61,30 @@
#define ON(x) do{pin_set(x ## _port, x ## _pin);}while(0)
#define OFF(x) do{pin_clear(x ## _port, x ## _pin);}while(0)
typedef enum{
BUZZER_OFF, // buzzer is off
BUZZER_ON, // continuous beeep
BUZZER_SHORT, // short beeps with longer pause
BUZZER_LONG // long beeps with shorter pause
} buzzer_state;
// Length of long and short time periods (ms)
#define LONG_BUZZER_PERIOD (4000)
#define LONG_BUZZER_PAUSE (6000)
#define SHORT_BUZZER_PERIOD (500)
#define SHORT_BUZZER_PAUSE (9500)
extern volatile uint32_t Tms;
extern volatile uint32_t Cooler0speed;
extern volatile uint32_t Cooler1speed;
extern volatile uint32_t Cooler1RPM;
extern uint8_t ledsON;
extern buzzer_state buzzer;
void HW_setup(void);
void adc_setup();
void iwdg_setup();
void pause_ms(uint32_t pause);
void Jump2Boot();
void buzzer_chk();
#endif // __HARDWARE_H__

View File

@ -93,6 +93,7 @@ int main(void){
IWDG->KR = IWDG_REFRESH;
cmd_parser(txt);
}
buzzer_chk();
}
return 0;
}

View File

@ -203,6 +203,30 @@ static inline void changeRPM(char *str){
}
}
static inline void buzzercmd(char cmd){
SEND("Buzzer: ");
switch(cmd){
case '0':
buzzer = BUZZER_OFF;
SEND("off");
break;
case '1':
buzzer = BUZZER_ON;
SEND("on");
break;
case 'l':
buzzer = BUZZER_LONG;
SEND("long beeps");
break;
case 's':
buzzer = BUZZER_SHORT;
SEND("short beeps");
break;
default:
SEND("wrong command");
}
}
/**
* @brief cmd_parser - command parsing
* @param txt - buffer with commands & data
@ -226,6 +250,10 @@ void cmd_parser(char *txt){
ADCget(txt[1]);
goto eof;
break;
case 'b': // buzzer
buzzercmd(txt[1]);
goto eof;
break;
case 'C': // Cooler RPM
coolerRPM(txt[1]);
goto eof;
@ -290,6 +318,7 @@ void cmd_parser(char *txt){
"'Ax' - get ADC raw value (x=0..7)\n"
"'a' - show current value of ADC1->DR\n"
"'B' - buttons' state\n"
"'bx' - buzzer: x==0 - off, x==1 - on, x==l - long beeps, x==s - short beeps\n"
"'Cx' - get cooler x (0/1) RPM\n"
"'D' - activate DFU mode\n"
"'M' - get MCU temperature\n"