From 797eb944129a5f840715f50eb41ae6ebc47a5f61 Mon Sep 17 00:00:00 2001 From: Eric Busch Date: Wed, 7 Feb 2018 10:18:30 -0500 Subject: [PATCH 1/3] remove alarm app, saving for a separate branch, and revert G ASCII LCD display Signed-off-by: Eric Busch --- firmware/Makefile | 2 +- firmware/applist.c | 4 - firmware/applist.h | 1 - firmware/apps/alarm.c | 189 ------------------------------------------ firmware/apps/alarm.h | 16 ---- firmware/lcdtext.c | 2 +- firmware/rtc.c | 3 +- 7 files changed, 3 insertions(+), 214 deletions(-) delete mode 100644 firmware/apps/alarm.c delete mode 100644 firmware/apps/alarm.h diff --git a/firmware/Makefile b/firmware/Makefile index 69c387f..26f09cc 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -12,7 +12,7 @@ modules=rtcasm.o main.o lcd.o lcdtext.o rtc.o keypad.o apps.o applist.o \ radio.o packet.o dmesg.o codeplug.o rng.o \ libs/assembler.o libs/morse.o -apps= apps/clock.o apps/alarm.o apps/rpn.o apps/hex.o apps/stopwatch.o apps/dice.o \ +apps= apps/clock.o apps/rpn.o apps/hex.o apps/stopwatch.o apps/dice.o \ apps/rngapp.o apps/tuner.o apps/morse.o apps/beacon.o apps/iclicker.o \ apps/submenu.o diff --git a/firmware/applist.c b/firmware/applist.c index 785cf01..a80c950 100644 --- a/firmware/applist.c +++ b/firmware/applist.c @@ -15,10 +15,6 @@ const struct app apps[]={ {.name="clock", .init=clock_init, .draw=clock_draw, .exit=clock_exit, .keypress=clock_keypress }, - //Alarm - {.name="alarm", .init=alarm_init, .draw=alarm_draw, .exit=alarm_exit, - .keypress=alarm_keypress - }, //Stopwatch {.name="timer", .init=stopwatch_init, .draw=stopwatch_draw, .exit=stopwatch_exit, .keypress=stopwatch_keypress diff --git a/firmware/applist.h b/firmware/applist.h index 3a763c6..4d6c25c 100644 --- a/firmware/applist.h +++ b/firmware/applist.h @@ -6,7 +6,6 @@ //Non-radio apps first. #include "apps/clock.h" -#include "apps/alarm.h" #include "apps/stopwatch.h" #include "apps/rpn.h" #include "apps/hex.h" diff --git a/firmware/apps/alarm.c b/firmware/apps/alarm.c deleted file mode 100644 index 7a95820..0000000 --- a/firmware/apps/alarm.c +++ /dev/null @@ -1,189 +0,0 @@ -/*! \file alarm.c - \brief Alarm clock application. - -*/ - -// for some reason this isn't in the msp430-gcc packages, but is in TI source -#define RTCAE (0x80) /* Real Time Clock Alarm enable */ - -#include -#include "api.h" - - -//! If non-zero, we are setting the alarm. -static int settingalarm=0; - - -//! Gets alarm set status -static int alarm_enabled() { - return (RTCAHOUR & RTCAE && RTCAMIN & RTCAE); -} - -//! Toggle alarm enable bits -static void toggle_alarm(int enable) { - if (enable){ - RTCAHOUR |= RTCAE; - RTCAMIN |= RTCAE; - } else { - RTCAHOUR &= ~RTCAE; - RTCAMIN &= ~RTCAE; - } -} - - -//! Draws the alarm. -static void draw_alarm(){ - unsigned int hour=RTCAHOUR & ~RTCAE; - unsigned int min=RTCAMIN & ~RTCAE; - - lcd_digit(7,hour/10); - lcd_digit(6,hour%10); - lcd_cleardigit(5); //Space - setcolon(1); - lcd_digit(4,min/10); - lcd_digit(3,min%10); - lcd_cleardigit(2); //Space - lcd_char(1, 'a'); - lcd_char(0, 'l'); - - if(alarm_enabled()) - setplus(1); - else - setplus(0); - - setam(hour<12); - setpm(hour>=12); -} - - -//! Draws whatever is being set -static void draw_settingalarm(){ - - unsigned int hour=RTCAHOUR & ~RTCAE; - unsigned int min=RTCAMIN & ~RTCAE; - - lcd_digit(7,hour/10); - lcd_digit(6,hour%10); - lcd_cleardigit(5); //Space - setcolon(1); - lcd_digit(4,min/10); - lcd_digit(3,min%10); - lcd_cleardigit(2); //Space - lcd_cleardigit(1); //Space - lcd_cleardigit(0); //Space - - setam(hour<12); - setpm(hour>=12); - - static int flicker=0; - - flicker^=1; - - switch(settingalarm){ - case 1: //Hour - if(flicker) - lcd_cleardigit(7); - break; - case 2: - if(flicker) - lcd_cleardigit(6); - break; - case 3: //Minute - if(flicker) - lcd_cleardigit(4); - break; - case 4: - if(flicker) - lcd_cleardigit(3); - break; - } -} - - -//! Entry to the alarm app. -void alarm_init(){ - lcd_zero(); -} -//! Exit alarm when the sidebutton is pressed, unless we are programming. -int alarm_exit(){ - if(settingalarm){ - //Setting the alarm, so jump to next digit. - settingalarm++; - if (settingalarm > 4) - settingalarm=0; - return 1; - }else{ - //Not setting the alarm, so just move on to next app. - setplus(0); - return 0; - } -} - -static char lastchar=0; - -//! Draws the alarm time in the main application. -void alarm_draw(){ - static char ch=0; - - if(ch!=lastchar) - lcd_zero(); - - ch=lastchar; - - /* The SET button will move us into the programming mode. */ - if(sidebutton_set()){ - settingalarm=!settingalarm; - } - - if(settingalarm) - draw_settingalarm(); - else - draw_alarm(); -} - -//! A button has been pressed for the alarm. -void alarm_keypress(char ch){ - unsigned char inputdigit=0; - lastchar=ch; - - if(settingalarm){ - //We only handle numbers here. - if((ch&0x30)==0x30) - inputdigit=ch&0x0F; - else - return; - - switch(settingalarm){ - case 1: //Hour - RTCAHOUR = inputdigit*10+RTCAHOUR%10; - settingalarm++; - break; - case 2: - RTCAHOUR = RTCAHOUR-RTCAHOUR%10+inputdigit; - settingalarm++; - break; - case 3: //Minute - RTCAMIN = inputdigit*10+RTCAMIN%10; - settingalarm++; - break; - case 4: - RTCAMIN = RTCAMIN-RTCAMIN%10+inputdigit; - settingalarm++; - break; - default: - /* Once we've exceeded the count, it's time to return to the - normal mode. - */ - settingalarm=0; - } - } else { - switch(ch){ - case '4': - if (alarm_enabled()) - toggle_alarm(0); - else - toggle_alarm(1); - break; - } - } -} diff --git a/firmware/apps/alarm.h b/firmware/apps/alarm.h deleted file mode 100644 index c0fcef2..0000000 --- a/firmware/apps/alarm.h +++ /dev/null @@ -1,16 +0,0 @@ -/*! \file alarm.h - \brief alarm application. -*/ - -//! Initialize the alarm. -void alarm_init(); -//! Exit to the next application. -int alarm_exit(); -//! Draw the alarm. -void alarm_draw(); - -//! A button has been pressed for the alarm. -void alarm_keypress(char ch); - -//! Toggle the alarm -void toggle_alarm(int enable); diff --git a/firmware/lcdtext.c b/firmware/lcdtext.c index 00ae5c4..8bac931 100644 --- a/firmware/lcdtext.c +++ b/firmware/lcdtext.c @@ -72,7 +72,7 @@ const int letterfont[]={ E|G|C|D|B, //D A|F|E|G|D, //E A|G|F|E, //F - A|F|E|C|D, //G + A|F|G|E|C|D, //G F|G|E|C, //h F|E, //I, distinguished from a 1 by being on the left side. E|B|C|D, //J diff --git a/firmware/rtc.c b/firmware/rtc.c index ce27435..ae8580f 100644 --- a/firmware/rtc.c +++ b/firmware/rtc.c @@ -160,8 +160,7 @@ void __attribute__ ((interrupt(RTC_VECTOR))) RTC_ISR (void){ case 4: break; // RTCTEVIFG case 6: // RTCAIFG Alarm //beep beep - lcd_string("alarm"); - __delay_cycles(2000); + break; case 8: break; // RT0PSIFG case 10: break; // RT1PSIFG From 74359d0ceb86f1cb3f6f4d90832c5039b4f1c6cb Mon Sep 17 00:00:00 2001 From: Travis Goodspeed Date: Wed, 7 Feb 2018 17:14:21 -0500 Subject: [PATCH 2/3] keypad.c now avoids the buzzer pin. #77 --- firmware/keypad.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/firmware/keypad.c b/firmware/keypad.c index 817c842..dcbc8d6 100644 --- a/firmware/keypad.c +++ b/firmware/keypad.c @@ -20,16 +20,19 @@ void key_init(){ /* Columns 2.2, 2.1, 2.0, and 1.7 are set to output mode pulled high, so that any low row indicates a button press. */ - P2SEL=0x00; //All of port 2 are IO. - P2DIR=BIT2|BIT1|BIT0; //Rows are input, columns are output. + P2SEL&=~0x7F; //All of port 2 except the buzzer are IO. + P2DIR=BIT2|BIT1|BIT0; //These columns are output. P2REN|=0xFF; //All resistor. P2OUT=BIT2|BIT1|BIT0; //Pull all of them down. P1SEL&=~0x80; //P1.7 is IO. - P1DIR|=0x80; //P1.7 is output. + P1DIR|=0x80; //P1.7 is output. P1REN|=0x80; P1OUT|=0x80; //Output high. + + P2DIR|=BIT7; // Buzzer is on P2.7. + //Trigger interrupts for keypresses so we needn't scan. P2IE|=BIT2|BIT1|BIT0; } @@ -44,8 +47,8 @@ int key_row(){ int row; P1DIR|=0x80; //P1.7 out. P1OUT|=0x80; //P1.7 high. - P2DIR= 0x07; //P2.0, 2.1, 2.2 out. - P2OUT= 0x07; //P2.0, 2.1, 2.2 high. + P2DIR|=0x07; //P2.0, 2.1, 2.2 out. + P2OUT|=0x07; //P2.0, 2.1, 2.2 high. //We'll return this result, but after cleaning up. row=(P2IN>>3)&0x0F; @@ -60,8 +63,11 @@ int key_col(){ int col; P1DIR&=~0x80; //Input P1OUT&=~0x80; //Low - P2DIR= 0xF8; //P2.1.3, 2.4, 2.5, 2.6 out - P2OUT= 0xF8; //P2.1.3, 2.4, 2.5, 2.6 high + + P2DIR&=~0x07; //P2.3, 2.4, 2.5, 2.6 out + P2DIR|= 0x78; + P2OUT&=~0x07; //P2.3, 2.4, 2.5, 2.6 high + P2OUT|= 0x78; //We'll return this result, but after cleaning up. col=((P2IN&0x7)<<1) | ((P2IN&0x80)>>7); From ad86cbab6783159515aadb81edd3894b9f044fa8 Mon Sep 17 00:00:00 2001 From: Travis Goodspeed Date: Wed, 7 Feb 2018 20:38:41 -0500 Subject: [PATCH 3/3] Basics of a buzzer. Needs some hardware modifications. #77 --- firmware/Makefile | 2 +- firmware/api.h | 1 + firmware/buzz.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++ firmware/buzz.h | 10 ++++++++ firmware/main.c | 9 +++++++ 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 firmware/buzz.c create mode 100644 firmware/buzz.h diff --git a/firmware/Makefile b/firmware/Makefile index 26f09cc..1c691fa 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -8,7 +8,7 @@ CC = msp430-gcc -mmcu=cc430f6137 -Wall -I. -Os BSL = ../bin/cc430-bsl.py -r 38400 -p $(PORT) modules=rtcasm.o main.o lcd.o lcdtext.o rtc.o keypad.o apps.o applist.o \ - sidebutton.o power.o uart.o monitor.o ucs.o \ + sidebutton.o power.o uart.o monitor.o ucs.o buzz.o \ radio.o packet.o dmesg.o codeplug.o rng.o \ libs/assembler.o libs/morse.o diff --git a/firmware/api.h b/firmware/api.h index aef1444..8568fbf 100644 --- a/firmware/api.h +++ b/firmware/api.h @@ -27,6 +27,7 @@ #include "codeplug.h" #include "power.h" #include "dmesg.h" +#include "buzz.h" #include "gittag.h" //Autogenerated //Handy libraries. These are tested host-side. diff --git a/firmware/buzz.c b/firmware/buzz.c new file mode 100644 index 0000000..9522973 --- /dev/null +++ b/firmware/buzz.c @@ -0,0 +1,60 @@ +/*! \file buzz.c + \brief Handy buzzer functions. + + These are currently untested, as the buzzer causes the GoodWatch20 + to glitch out. We hope to have proper buzzer support in the + GoodWatch21. +*/ + +#include + +#include + +//! Make a quick buzz. +void buzz(unsigned int count){ + //Start the timer. + if(count){ + //Output select mode for P2.7. + P2DIR|=0x80; + P2SEL|=0x80; + + //P2.7 might need high drive strength for the piezo. + //P2DS|=0x80; + + + TA1CCR0 = count; + TA1CTL |= MC__UP; + }else{ + //Stop the timer when it's not in use. + TA1CTL = TACLR | TASSEL__SMCLK | MC__STOP; + + //Input mode for the pin, so we don't accidentally leak power. + P2DIR&=~0x80; + P2SEL&=~0x80; + } +} + + +//! Initializes the buzzer port. +void buzz_init(){ + TA1CTL=0; + + //Unlock port mapping. + PMAPKEYID=0x2d52; + if(PMAPCTL&1) + printf("Ugh, port mapping is locked.\n"); + + //Route timera1 to the pin. This might conflict with rng.c. + P2MAP7=PM_TA1CCR0A;; + + //Lock port mapping. + PMAPKEYID=0x96a5; + + + TA1CTL = TACLR | TASSEL__SMCLK | MC__STOP; + TA1CCTL0 = OUTMOD_4; + TA1CCTL0 &= ~CCIE; + + P2SEL|=0x80; +} + diff --git a/firmware/buzz.h b/firmware/buzz.h new file mode 100644 index 0000000..a1308b0 --- /dev/null +++ b/firmware/buzz.h @@ -0,0 +1,10 @@ +/*! \file buzz.h + \brief Handy buzzer functions. +*/ + +//! Initializes the buzzer port. +void buzz_init(); + +//! Make a quick buzz. +void buzz(int); + diff --git a/firmware/main.c b/firmware/main.c index 2d617d5..88738cc 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -89,6 +89,15 @@ int main(void) { lcd_string("OSC INIT"); ucs_init(); + /* TODO Enable this once we have hardware with a working buzzer. + + lcd_zero(); + printf("buzz "); + lcd_string("BUZZINIT"); + buzz_init(); + buzz(1024); + */ + lcd_zero(); lcd_string("UARTINIT"); uart_init();