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);
|
||||
|
||||
|
||||
@@ -56,18 +56,17 @@ X Pin_4 4 -200 -200 150 R 50 50 1 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# Connector_Generic_Conn_01x10
|
||||
# Connector_Generic_Conn_01x09
|
||||
#
|
||||
DEF Connector_Generic_Conn_01x10 J 0 40 Y N 1 F N
|
||||
DEF Connector_Generic_Conn_01x09 J 0 40 Y N 1 F N
|
||||
F0 "J" 0 500 50 H V C CNN
|
||||
F1 "Connector_Generic_Conn_01x10" 0 -600 50 H V C CNN
|
||||
F1 "Connector_Generic_Conn_01x09" 0 -500 50 H V C CNN
|
||||
F2 "" 0 0 50 H I C CNN
|
||||
F3 "" 0 0 50 H I C CNN
|
||||
$FPLIST
|
||||
Connector*:*_1x??_*
|
||||
$ENDFPLIST
|
||||
DRAW
|
||||
S -50 -495 0 -505 1 1 6 N
|
||||
S -50 -395 0 -405 1 1 6 N
|
||||
S -50 -295 0 -305 1 1 6 N
|
||||
S -50 -195 0 -205 1 1 6 N
|
||||
@@ -77,9 +76,8 @@ S -50 105 0 95 1 1 6 N
|
||||
S -50 205 0 195 1 1 6 N
|
||||
S -50 305 0 295 1 1 6 N
|
||||
S -50 405 0 395 1 1 6 N
|
||||
S -50 450 50 -550 1 1 10 f
|
||||
S -50 450 50 -450 1 1 10 f
|
||||
X Pin_1 1 -200 400 150 R 50 50 1 1 P
|
||||
X Pin_10 10 -200 -500 150 R 50 50 1 1 P
|
||||
X Pin_2 2 -200 300 150 R 50 50 1 1 P
|
||||
X Pin_3 3 -200 200 150 R 50 50 1 1 P
|
||||
X Pin_4 4 -200 100 150 R 50 50 1 1 P
|
||||
@@ -116,6 +114,26 @@ X - 2 0 -200 100 U 50 50 1 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# Device_Buzzer
|
||||
#
|
||||
DEF Device_Buzzer BZ 0 1 Y N 1 F N
|
||||
F0 "BZ" 150 50 50 H V L CNN
|
||||
F1 "Device_Buzzer" 150 -50 50 H V L CNN
|
||||
F2 "" -25 100 50 V I C CNN
|
||||
F3 "" -25 100 50 V I C CNN
|
||||
$FPLIST
|
||||
*Buzzer*
|
||||
$ENDFPLIST
|
||||
DRAW
|
||||
A 0 0 125 -899 899 0 1 0 N 0 -125 0 125
|
||||
P 2 0 1 0 -65 75 -45 75 N
|
||||
P 2 0 1 0 -55 85 -55 65 N
|
||||
P 2 0 1 0 0 125 0 -125 N
|
||||
X - 1 -100 100 100 R 50 50 1 1 P
|
||||
X + 2 -100 -100 100 R 50 50 1 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# Device_C
|
||||
#
|
||||
DEF Device_C C 0 10 N Y 1 F N
|
||||
@@ -220,6 +238,25 @@ X A 2 150 0 100 L 50 50 1 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# Device_Q_NPN_BCE
|
||||
#
|
||||
DEF Device_Q_NPN_BCE Q 0 0 Y N 1 F N
|
||||
F0 "Q" 200 50 50 H V L CNN
|
||||
F1 "Device_Q_NPN_BCE" 200 -50 50 H V L CNN
|
||||
F2 "" 200 100 50 H I C CNN
|
||||
F3 "" 0 0 50 H I C CNN
|
||||
DRAW
|
||||
C 50 0 111 0 1 10 N
|
||||
P 2 0 1 0 25 25 100 100 N
|
||||
P 3 0 1 0 25 -25 100 -100 100 -100 N
|
||||
P 3 0 1 20 25 75 25 -75 25 -75 N
|
||||
P 5 0 1 0 50 -70 70 -50 90 -90 50 -70 50 -70 F
|
||||
X B 1 -200 0 225 R 50 50 1 1 I
|
||||
X C 2 100 200 100 D 50 50 1 1 P
|
||||
X E 3 100 -200 100 U 50 50 1 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# Device_Q_PNP_BCE
|
||||
#
|
||||
DEF Device_Q_PNP_BCE Q 0 0 Y N 1 F N
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -12,16 +12,6 @@ NetIExt=net
|
||||
version=1
|
||||
LibDir=
|
||||
[eeschema/libraries]
|
||||
[schematic_editor]
|
||||
version=1
|
||||
PageLayoutDescrFile=
|
||||
PlotDirectoryName=../../../Pulpit/
|
||||
SubpartIdSeparator=0
|
||||
SubpartFirstId=65
|
||||
NetFmtName=Pcbnew
|
||||
SpiceAjustPassiveValues=0
|
||||
LabSize=39
|
||||
ERC_TestSimilarLabels=1
|
||||
[pcbnew]
|
||||
version=1
|
||||
PageLayoutDescrFile=
|
||||
@@ -257,3 +247,13 @@ uViaDrill=0.1
|
||||
dPairWidth=0.2
|
||||
dPairGap=0.25
|
||||
dPairViaGap=0.25
|
||||
[schematic_editor]
|
||||
version=1
|
||||
PageLayoutDescrFile=
|
||||
PlotDirectoryName=../../../Pulpit/
|
||||
SubpartIdSeparator=0
|
||||
SubpartFirstId=65
|
||||
NetFmtName=Pcbnew
|
||||
SpiceAjustPassiveValues=0
|
||||
LabSize=39
|
||||
ERC_TestSimilarLabels=1
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user