Add support for buzzer
This commit is contained in:
@@ -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;
|
||||
}
|
||||
23
firmware/buzzer.c
Normal file
23
firmware/buzzer.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <avr/io.h>
|
||||
#include "common.h"
|
||||
#include "buzzer.h"
|
||||
#include "ptimer.h"
|
||||
#include "config.h"
|
||||
|
||||
|
||||
void buz_init(void)
|
||||
{
|
||||
R_DDR(BUZZER_PORT) |= 1<<BUZZER;
|
||||
R_PORT(BUZZER_PORT) &= ~(1<<BUZZER);
|
||||
}
|
||||
|
||||
void buz_on(void)
|
||||
{
|
||||
if(ram_cfg.buz_en) tim_buz = BUZZER_DURATION;
|
||||
}
|
||||
|
||||
void buz_handle_event(void)
|
||||
{
|
||||
if(tim_buz) R_PORT(BUZZER_PORT) |= 1<<BUZZER;
|
||||
else R_PORT(BUZZER_PORT) &= ~(1<<BUZZER);
|
||||
}
|
||||
14
firmware/buzzer.h
Normal file
14
firmware/buzzer.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef __BUZZER_H__
|
||||
#define __BUZZER_H__
|
||||
|
||||
#define BUZZER_PORT C
|
||||
#define BUZZER 7
|
||||
|
||||
#define BUZZER_DURATION 10
|
||||
|
||||
void buz_init(void);
|
||||
void buz_on(void);
|
||||
void buz_handle_event(void);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -3,6 +3,7 @@
|
||||
struct CFG ram_cfg;
|
||||
struct CFG eem_cfg EEMEM;
|
||||
const struct CFG pgm_cfg PROGMEM = {
|
||||
BUZ_EN,
|
||||
LED_BRIGHTNESS,
|
||||
NIGHT_MODE
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#define AUTO_BTNES_SIZE 4
|
||||
|
||||
#define BUZ_EN 1
|
||||
#define LED_BRIGHTNESS 7
|
||||
#define NIGHT_MODE { -1, { 0, 0 }, { 0, 0 } }
|
||||
|
||||
@@ -19,6 +20,7 @@ struct NIGHTM_CFG
|
||||
|
||||
struct CFG
|
||||
{
|
||||
uint8_t buz_en;
|
||||
uint8_t led_btnes;
|
||||
struct NIGHTM_CFG night_mode;
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
#include "keyboard.h"
|
||||
#include "buzzer.h"
|
||||
#include "debounce.h"
|
||||
#include "rtc.h"
|
||||
#include "led.h"
|
||||
@@ -9,25 +10,29 @@
|
||||
uint8_t k_inc_hour, k_inc_minute, k_inc_second, k_inc_brightness;
|
||||
|
||||
void inc_hour(void)
|
||||
{
|
||||
{
|
||||
rtc_inc_time(HOUR);
|
||||
buz_on();
|
||||
}
|
||||
|
||||
void inc_minute(void)
|
||||
{
|
||||
{
|
||||
rtc_inc_time(MINUTE);
|
||||
buz_on();
|
||||
}
|
||||
|
||||
void inc_second(void)
|
||||
{
|
||||
{
|
||||
rtc_inc_time(SECOND);
|
||||
buz_on();
|
||||
}
|
||||
|
||||
void inc_brightness(void)
|
||||
{
|
||||
{
|
||||
if(++ram_cfg.led_btnes > 7) ram_cfg.led_btnes = 0;
|
||||
led_set_btnes(ram_cfg.led_btnes);
|
||||
dump_ram2eem();
|
||||
buz_on();
|
||||
}
|
||||
|
||||
void kbd_init(void)
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<<WGM21);
|
||||
TCCR2 |= (1<<CS22) | (1<<CS21) | (1<<CS20);
|
||||
@@ -18,4 +20,5 @@ void ptimer_init(void)
|
||||
ISR(TIMER2_COMP_vect)
|
||||
{
|
||||
if(tim_debounce) --tim_debounce;
|
||||
if(tim_buz) --tim_buz;
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
#define __PTIMER_H__
|
||||
|
||||
extern volatile uint16_t tim_debounce;
|
||||
extern volatile uint8_t tim_buz;
|
||||
|
||||
void ptimer_init(void);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user