diff --git a/firmware/at.c b/firmware/at.c index a292c73..a30a13e 100644 --- a/firmware/at.c +++ b/firmware/at.c @@ -23,16 +23,18 @@ int8_t cmd_at_tim_handler(uint8_t mode, char* arg); int8_t cmd_at_dat_handler(uint8_t mode, char* arg); int8_t cmd_at_bts_handler(uint8_t mode, char* arg); int8_t cmd_at_ngt_handler(uint8_t mode, char* arg); +int8_t cmd_at_buz_handler(uint8_t mode, char* arg); -#define AT_NUM 7 +#define AT_NUM 8 const struct AT_CMD at_commands[AT_NUM] PROGMEM = { - { "AT", cmd_at_handler }, - { "ATI", cmd_ati_handler }, - { "AT+RST", cmd_at_rst_handler }, - { "AT+TIM", cmd_at_tim_handler }, - { "AT+DAT", cmd_at_dat_handler }, - { "AT+BTS", cmd_at_bts_handler }, - { "AT+NGT", cmd_at_ngt_handler } + { "AT", cmd_at_handler }, + { "ATI", cmd_ati_handler }, + { "AT+RST", cmd_at_rst_handler }, + { "AT+TIM", cmd_at_tim_handler }, + { "AT+DAT", cmd_at_dat_handler }, + { "AT+BTS", cmd_at_bts_handler }, + { "AT+NGT", cmd_at_ngt_handler }, + { "AT+BUZ", cmd_at_buz_handler } }; static struct RTC_DATA* rtc_data; @@ -317,5 +319,35 @@ int8_t cmd_at_ngt_handler(uint8_t mode, char* arg) uart_puts_P(PSTR("AT+NGT=(-1|0-7),(0-23),(0-59),(0-23),(0-59)\n\r")); } + return 0; +} + +int8_t cmd_at_buz_handler(uint8_t mode, char* arg) +{ + uint8_t buz_en; + + switch(mode) + { + case M_GET: + uart_puti(ram_cfg.buz_en, 10); + uart_puts("\n\r"); + break; + + case M_SET: + if(!strlen(arg)) return -1; + + buz_en = atoi(arg); + if(buz_en != 0 && buz_en != 1) return -1; + ram_cfg.buz_en = buz_en; + dump_ram2eem(); + uart_puts_P(PSTR("+BUZ=")); + uart_puti(buz_en, 10); + uart_puts("\n\r"); + break; + + case M_NORM: + uart_puts_P(PSTR("AT+BUZ=(0|1)\n\r")); + } + return 0; } \ No newline at end of file diff --git a/firmware/buzzer.c b/firmware/buzzer.c new file mode 100644 index 0000000..818d52e --- /dev/null +++ b/firmware/buzzer.c @@ -0,0 +1,23 @@ +#include +#include "common.h" +#include "buzzer.h" +#include "ptimer.h" +#include "config.h" + + +void buz_init(void) +{ + R_DDR(BUZZER_PORT) |= 1< 7) ram_cfg.led_btnes = 0; led_set_btnes(ram_cfg.led_btnes); dump_ram2eem(); + buz_on(); } void kbd_init(void) diff --git a/firmware/main.c b/firmware/main.c index 2afba87..1d8dee3 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -4,6 +4,7 @@ #include "ptimer.h" #include "config.h" #include "nightm.h" +#include "buzzer.h" #include "time.h" #include "uart.h" #include "i2c.h" @@ -24,6 +25,7 @@ int main() rtc_int0_init(); led_init(); uart_init(); + buz_init(); uart_bind_handler(at_handler); rtc_bind_handler(update_time); @@ -39,6 +41,7 @@ int main() kbd_handle_event(); uart_handle_event(uart_buf); rtc_handle_event(); + buz_handle_event(); } } diff --git a/firmware/ptimer.c b/firmware/ptimer.c index 362f4cb..5076104 100644 --- a/firmware/ptimer.c +++ b/firmware/ptimer.c @@ -3,10 +3,12 @@ #include "ptimer.h" volatile uint16_t tim_debounce; +volatile uint8_t tim_buz; void ptimer_init(void) { tim_debounce = 0; + tim_buz = 0; TCCR2 |= (1<