diff --git a/firmware/Makefile b/firmware/Makefile index 75e9bb4..1c691fa 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -7,12 +7,12 @@ 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 buzzer.o \ - sidebutton.o power.o uart.o monitor.o ucs.o \ +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 buzz.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/api.h b/firmware/api.h index b0c17ba..ca1d410 100644 --- a/firmware/api.h +++ b/firmware/api.h @@ -28,6 +28,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/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/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/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); 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/main.c b/firmware/main.c index b3e15a2..145b826 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(); diff --git a/firmware/rtc.c b/firmware/rtc.c index 5aab143..cd943ec 100644 --- a/firmware/rtc.c +++ b/firmware/rtc.c @@ -164,7 +164,6 @@ void __attribute__ ((interrupt(RTC_VECTOR))) RTC_ISR (void){ //! Sound the alarm alarm_trigger(); } - break; case 8: break; // RT0PSIFG case 10: break; // RT1PSIFG