├── main.c ├── logic ├── test.c ├── temperature.c ├── temperature.h ├── test.h ├── rfbsl.h ├── date.h ├── user.h ├── alarm.h ├── clock.h ├── battery.h ├── baro.h ├── acceleration.h ├── altitude.h ├── stopwatch.h ├── menu.h ├── rfsimpliciti.h ├── rfbsl.c ├── bluerobin.h ├── baro.c ├── battery.c ├── menu.c ├── alarm.c └── user.c ├── driver ├── bmp_ps.c ├── cma_ps.c ├── ez430_chronos_drivers.lib ├── rf1a.h ├── pmm.h ├── radio.h ├── adc12.h ├── cma_ps.h ├── cma_as.h ├── timer.h ├── buzzer.h ├── bmp_as.h ├── pmm.c ├── bmp_ps.h ├── as.h ├── ps.h ├── ports.h ├── adc12.c ├── radio.c ├── buzzer.c ├── cma_as.c ├── rf1a.c └── bmp_as.c ├── README.txt └── include └── project.h /main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vegos/MyChronos/HEAD/main.c -------------------------------------------------------------------------------- /logic/test.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vegos/MyChronos/HEAD/logic/test.c -------------------------------------------------------------------------------- /driver/bmp_ps.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vegos/MyChronos/HEAD/driver/bmp_ps.c -------------------------------------------------------------------------------- /driver/cma_ps.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vegos/MyChronos/HEAD/driver/cma_ps.c -------------------------------------------------------------------------------- /logic/temperature.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vegos/MyChronos/HEAD/logic/temperature.c -------------------------------------------------------------------------------- /logic/temperature.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vegos/MyChronos/HEAD/logic/temperature.h -------------------------------------------------------------------------------- /driver/ez430_chronos_drivers.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vegos/MyChronos/HEAD/driver/ez430_chronos_drivers.lib -------------------------------------------------------------------------------- /driver/rf1a.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Actual revision: $Revision: $ 4 | // Revision label: $Name: $ 5 | // Revision state: $State: $ 6 | // 7 | // ************************************************************************************************* 8 | // Radio core access functions. Taken from TI reference code for CC430. 9 | // ************************************************************************************************* 10 | 11 | // ************************************************************************************************* 12 | // Prototype section 13 | unsigned char Strobe(unsigned char strobe); 14 | unsigned char ReadSingleReg(unsigned char addr); 15 | void WriteSingleReg(unsigned char addr, unsigned char value); 16 | void ReadBurstReg(unsigned char addr, unsigned char *buffer, unsigned char count); 17 | void WriteBurstReg(unsigned char addr, unsigned char *buffer, unsigned char count); 18 | void ResetRadioCore(void); 19 | void WritePATable(unsigned char value); 20 | void WaitForXT2(void); 21 | -------------------------------------------------------------------------------- /driver/pmm.h: -------------------------------------------------------------------------------- 1 | //==================================================================== 2 | // File: PMM.h 3 | // 4 | // This file is used in conjunction with PMM.c to set the core 5 | // voltage level of a device. To set a core voltage level, call 6 | // SetVCore(level). See RF project(s) for example usage. 7 | // 8 | // Version 1.0 first 9 | // 07/14/07 10 | // 11 | //==================================================================== 12 | 13 | #ifndef __PMM 14 | #define __PMM 15 | 16 | //==================================================================== 17 | 18 | /** 19 | * Set the VCore to a new level 20 | * 21 | * \param level PMM level ID 22 | */ 23 | void SetVCore(unsigned char level); 24 | 25 | //==================================================================== 26 | 27 | /** 28 | * Set the VCore to a new higher level 29 | * 30 | * \param level PMM level ID 31 | */ 32 | void SetVCoreUp(unsigned char level); 33 | 34 | //==================================================================== 35 | 36 | /** 37 | * Set the VCore to a new Lower level 38 | * 39 | * \param level PMM level ID 40 | */ 41 | void SetVCoreDown(unsigned char level); 42 | 43 | #endif /* __PMM */ 44 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | 2 | MMMM MMMM ---------- CCCCCC - HH -------------------------------------------- 3 | MMM MMM CC CC HH 4 | MMMM MMMM CC HH 5 | MM MMM MM YY YY CC HHHHHH R RRRR OOOOO N NNNN OOOOO SSSSS 6 | MM M MM YY YY CC HH HH RR RR OO OO NN NN OO OO SS 7 | MM MM YY YY CC HH HH RR OO OO NN NN OO OO SSSSS 8 | MM MM YY YY CC CC HH HH RR OO OO NN NN OO OO SS 9 | MMMM MMMM YYYYYY CCCCCC HH HH RRRR OOOOO NN NN OOOOO SSSSS 10 | YY 11 | YY YY 12 | ------------- YYYYY -------------------------- (c)2013-2014, Antonis Maglaras - 13 | 14 | 15 | 16 | Texas Instruments eZ430 Chronos Development Kit 17 | 18 | http://www.ti.com/tool/ez430-chronos&DCMP=Chronos&HQS=Other+OT+chronos 19 | http://processors.wiki.ti.com/index.php/EZ430-Chronos 20 | 21 | 22 | MyChronos is a modified stock firmware (v.1.7/v.1.8) 23 | Or to be MORE specific: At least, it's a way for me to start learning and 24 | customizing the eZ430 to my needs :) 25 | 26 | Note that I have not include almost everything to make it a real import on CCS 27 | due to some errors when uploading. I will fix it someday in the near future! 28 | Till then, you can just replace the original firmware files (BUT don't forget 29 | to take a backup of your working set first :)). 30 | 31 | 32 | 33 | 34 | Menu Structure: 35 | --------------- 36 | 37 | Line 1: 38 | - Time (Up for Seconds) 39 | - Altitude 40 | - Temperature 41 | - Barometer in hPa 42 | - Alarm 43 | - Accelerometer Z-Axis (Up for X-Axis or Y-Axis) 44 | 45 | Line 2: 46 | - Date (Down for Year, 3-letters day of week name or 3-letters month name or 47 | 2-letters day-of-week or day) 48 | - Battery Voltage 49 | - Sync (for synching time with my ntp -- it does not sync altitude & 50 | temperature. I guess the watch knows better that my Linux machine what the 51 | temperature and the altitude is...) 52 | - Ctrl (Control: old PPT mode, for use with my custom python script) 53 | - Stopwatch 54 | - RESET (Down for resetting the temperature max/min statistics) 55 | - RFBSL (in my white-PCB is not working but I leave it for now...) 56 | 57 | 58 | 59 | To Do: 60 | ------ 61 | 62 | Add some statistics like Altitude Min/Max/Average, Temperature Average, 63 | Acceleration Peak, free-fall counter, maximum acceleration/difference from 64 | start etc... 65 | -------------------------------------------------------------------------------- /driver/radio.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef RADIO_H_ 37 | #define RADIO_H_ 38 | 39 | extern void radio_reset(void); 40 | extern void radio_powerdown(void); 41 | extern void radio_sxoff(void); 42 | extern void radio_idle(void); 43 | extern void open_radio(void); 44 | extern void close_radio(void); 45 | extern void pmm_set_high_current_mode(void); 46 | extern void pmm_set_low_current_mode(void); 47 | 48 | #endif /*RADIO_H_ */ 49 | -------------------------------------------------------------------------------- /logic/test.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | // Test functions. 36 | // ************************************************************************************************* 37 | 38 | #ifndef TEST_H_ 39 | #define TEST_H_ 40 | 41 | // ************************************************************************************************* 42 | // Extern section 43 | extern void test_mode(void); 44 | extern void display_all_on(void); 45 | extern void display_all_off(void); 46 | 47 | #endif /*TEST_H_ */ 48 | -------------------------------------------------------------------------------- /logic/rfbsl.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef RFBSL_H_ 37 | #define RFBSL_H_ 38 | 39 | // ************************************************************************************************* 40 | // Prototypes section 41 | extern void sx_rfbsl(u8 line); 42 | extern void display_rfbsl(u8 line, u8 update); 43 | 44 | // ************************************************************************************************* 45 | // Defines section 46 | 47 | // Entry point of of the Flash Updater in BSL memory 48 | #define CALL_RFSBL() ((void (*)()) 0x1000)() 49 | 50 | 51 | // ************************************************************************************************* 52 | // Global Variable section 53 | extern u8 rfBSL_button_confirmation; 54 | 55 | #endif /*RFBSL_H_ */ 56 | -------------------------------------------------------------------------------- /driver/adc12.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef ADC12_H_ 37 | #define ADC12_H_ 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | 42 | // ************************************************************************************************* 43 | // Prototypes section 44 | extern u16 adc12_single_conversion(u16 ref, u16 sht, u16 channel); 45 | 46 | // ************************************************************************************************* 47 | // Defines section 48 | 49 | // ************************************************************************************************* 50 | // Global Variable section 51 | extern u16 adc12_result; 52 | extern u8 adc12_data_ready; 53 | 54 | // ************************************************************************************************* 55 | // Extern section 56 | 57 | #endif /*ADC12_H_ */ 58 | -------------------------------------------------------------------------------- /driver/cma_ps.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef CMA_PS_H_ 37 | #define CMA_PS_H_ 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | 42 | // ************************************************************************************************* 43 | // Prototypes section 44 | extern void cma_ps_init(void); 45 | extern void cma_ps_start(void); 46 | extern void cma_ps_stop(void); 47 | extern u32 cma_ps_get_pa(void); 48 | extern u16 cma_ps_get_temp(void); 49 | 50 | // ************************************************************************************************* 51 | // Defines section 52 | 53 | // ************************************************************************************************* 54 | // Global Variable section 55 | 56 | // ************************************************************************************************* 57 | // Extern section 58 | 59 | #endif /*CMA_PS_H_ */ 60 | -------------------------------------------------------------------------------- /driver/cma_as.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef CMA_AS_H_ 37 | #define CMA_AS_H_ 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | 42 | // ************************************************************************************************* 43 | // Prototypes section 44 | extern void cma_as_start(void); 45 | extern void cma_as_stop(void); 46 | extern u8 cma_as_read_register(u8 bAddress); 47 | extern u8 cma_as_write_register(u8 bAddress, u8 bData); 48 | extern void cma_as_get_data(u8 * data); 49 | 50 | // ************************************************************************************************* 51 | // Defines section 52 | 53 | // ************************************************************************************************* 54 | // Global Variable section 55 | 56 | // ************************************************************************************************* 57 | // Extern section 58 | 59 | #endif /*CMA_AS_H_ */ 60 | -------------------------------------------------------------------------------- /logic/date.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef DATE_H_ 37 | #define DATE_H_ 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | 42 | // ************************************************************************************************* 43 | // Prototypes section 44 | extern void reset_date(void); 45 | extern void add_day(void); 46 | extern void mx_date(u8 line); 47 | extern void sx_date(u8 line); 48 | extern void display_date(u8 line, u8 update); 49 | 50 | // ************************************************************************************************* 51 | // Defines section 52 | 53 | // ************************************************************************************************* 54 | // Global Variable section 55 | struct date 56 | { 57 | u8 display; // Toggles view between DISPLAY_DEFAULT_VIEW = DD.MM and 58 | // DISPLAY_ALTERNATIVE_VIEW = YYYY 59 | u8 day; 60 | u8 month; 61 | u16 year; 62 | u8 DayOfWeek; 63 | }; 64 | extern struct date sDate; 65 | 66 | // ************************************************************************************************* 67 | // Extern section 68 | 69 | #endif /*DATE_H_ */ 70 | -------------------------------------------------------------------------------- /logic/user.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef USER_H_ 37 | #define USER_H_ 38 | 39 | // ************************************************************************************************* 40 | // Defines section 41 | #define SETVALUE_ROLLOVER_VALUE BIT0 42 | #define SETVALUE_DISPLAY_VALUE BIT1 43 | #define SETVALUE_DISPLAY_ARROWS BIT2 44 | #define SETVALUE_DISPLAY_SELECTION BIT3 45 | #define SETVALUE_FAST_MODE BIT4 46 | #define SETVALUE_NEXT_VALUE BIT5 47 | 48 | // ************************************************************************************************* 49 | // Prototypes section 50 | extern u8 *select_view_style(u8 line, u8 * view1, u8 * view2); 51 | 52 | extern void (*fptr_setValue_display_function1)(u8 segments, u32 value, u8 digits, u8 blanks); 53 | extern void set_value(s32 * value, u8 digits, u8 blanks, s32 limitLow, s32 limitHigh, u16 mode, 54 | u8 segments, 55 | void (*fptr_setValue_display_function1)(u8 segments, u32 value, u8 digits, 56 | u8 blanks)); 57 | extern void dummy(u8 line); 58 | 59 | #endif /*USER_H_ */ 60 | -------------------------------------------------------------------------------- /driver/timer.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef TIMER_H_ 37 | #define TIMER_H_ 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | 42 | // ************************************************************************************************* 43 | // Prototypes section 44 | extern void Timer0_Init(void); 45 | extern void Timer0_Start(void); 46 | extern void Timer0_Stop(void); 47 | extern void Timer0_A3_Start(u16 ticks); 48 | extern void Timer0_A3_Stop(void); 49 | extern void Timer0_A4_Delay(u16 ticks); 50 | 51 | extern void (*fptr_Timer0_A3_function)(void); 52 | 53 | // ************************************************************************************************* 54 | // Defines section 55 | struct timer 56 | { 57 | // Timer0_A3 periodic delay 58 | u16 timer0_A3_ticks; 59 | }; 60 | extern struct timer sTimer; 61 | 62 | // Trigger reset when all buttons are pressed 63 | #define BUTTON_RESET_SEC (3u) 64 | 65 | // ************************************************************************************************* 66 | // Global Variable section 67 | 68 | // ************************************************************************************************* 69 | // Extern section 70 | 71 | #endif /*TIMER_H_ */ 72 | -------------------------------------------------------------------------------- /logic/alarm.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | // ************************************************************************************************* 37 | // Include section 38 | 39 | // ************************************************************************************************* 40 | // Prototypes section 41 | 42 | // internal functions 43 | extern void reset_alarm(void); 44 | extern void check_alarm(void); 45 | extern void stop_alarm(void); 46 | 47 | // menu functions 48 | extern void sx_alarm(u8 line); 49 | extern void mx_alarm(u8 line); 50 | extern void display_alarm(u8 line, u8 update); 51 | 52 | // ************************************************************************************************* 53 | // Defines section 54 | 55 | // Alarm states 56 | #define ALARM_DISABLED (0u) 57 | #define ALARM_ENABLED (1u) 58 | #define ALARM_ON (2u) 59 | 60 | // Keep alarm for 10 on-off cycles 61 | #define ALARM_ON_DURATION (10u) 62 | 63 | // ************************************************************************************************* 64 | // Global Variable section 65 | struct alarm 66 | { 67 | u8 state; // ALARM_DISABLED, ALARM_ENABLED, ALARM_ON 68 | u8 duration; // Alarm duration 69 | u8 hour; // Alarm hour 70 | u8 minute; // Alarm minute 71 | }; 72 | extern struct alarm sAlarm; 73 | 74 | // ************************************************************************************************* 75 | // Extern section 76 | -------------------------------------------------------------------------------- /logic/clock.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef CLOCK_H_ 37 | #define CLOCK_H_ 38 | 39 | // ************************************************************************************************* 40 | // Defines section 41 | 42 | // Definitions for time format 43 | #define TIMEFORMAT_24H (0u) 44 | #define TIMEFORMAT_12H (1u) 45 | 46 | // ************************************************************************************************* 47 | // Prototypes section 48 | extern void reset_clock(void); 49 | extern void sx_time(u8 line); 50 | extern void mx_time(u8 line); 51 | extern void clock_tick(void); 52 | extern void display_selection_Timeformat1(u8 segments, u32 index, u8 digits, u8 blanks); 53 | extern void display_time(u8 line, u8 update); 54 | 55 | // English units support 56 | extern void calc_24H_to_12H(u8 * hours, u8 * timeAM); 57 | extern u8 convert_hour_to_12H_format(u8 hour); 58 | extern u8 is_hour_am(u8 hour); 59 | 60 | // ************************************************************************************************* 61 | // Global Variable section 62 | struct time 63 | { 64 | u32 system_time; // Global system time. Used to calculate last activity 65 | u32 last_activity; // Inactivity detection (exits set_value() function) 66 | u8 drawFlag; // Flag to minimize display updates 67 | u8 line1ViewStyle; // Viewing style 68 | u8 hour; // Time data 69 | u8 minute; // Time data 70 | u8 second; // Time data 71 | }; 72 | extern struct time sTime; 73 | 74 | #endif /*CLOCK_H_ */ 75 | -------------------------------------------------------------------------------- /logic/battery.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef BATTERY_H_ 37 | #define BATTERY_H_ 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | 42 | // ************************************************************************************************* 43 | // Prototypes section 44 | 45 | // Internal functions 46 | extern void reset_batt_measurement(void); 47 | extern void battery_measurement(void); 48 | 49 | // Menu functions 50 | extern void display_battery_V(u8 line, u8 update); 51 | 52 | // ************************************************************************************************* 53 | // Defines section 54 | 55 | // Battery high voltage threshold 56 | #define BATTERY_HIGH_THRESHOLD (360u) 57 | 58 | // Battery end of life voltage threshold -> disable radio, show "lobatt" message 59 | #define BATTERY_LOW_THRESHOLD (240u) 60 | 61 | // Show "lobatt" message every n seconds 62 | #define BATTERY_LOW_MESSAGE_CYCLE (15u) 63 | 64 | // ************************************************************************************************* 65 | // Global Variable section 66 | struct batt 67 | { 68 | menu_t state; // MENU_ITEM_NOT_VISIBLE, MENU_ITEM_VISIBLE 69 | u8 lobatt_display; // Counter for alternating "lobatt" display 70 | u16 voltage; // Battery voltage 71 | s16 offset; // Battery voltage offset 72 | }; 73 | extern struct batt sBatt; 74 | 75 | // ************************************************************************************************* 76 | // Extern section 77 | 78 | #endif /*BATTERY_H_ */ 79 | -------------------------------------------------------------------------------- /logic/baro.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef BARO_H_ 37 | #define BARO_H_ 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | 42 | // ************************************************************************************************* 43 | // Prototypes section 44 | extern u8 is_barometer_measurement(void); 45 | extern void start_barometer_measurement(void); 46 | extern void stop_barometer_measurement(void); 47 | extern void do_barometer_measurement(u8 filter); 48 | 49 | // menu functions 50 | extern void display_barometer(u8 line, u8 update); 51 | 52 | // ************************************************************************************************* 53 | // Defines section 54 | #define BAROMETER_MEASUREMENT_TIMEOUT (1 * 60u) // Stop barometer measurement after 1 minute to 55 | // save battery 56 | 57 | // ************************************************************************************************* 58 | // Global Variable section 59 | struct baro 60 | { 61 | menu_t state; // MENU_ITEM_NOT_VISIBLE, MENU_ITEM_VISIBLE 62 | u32 pressure; // Pressure (Pa) 63 | s16 barometer; // Altitude (m) 64 | s16 barometer_offset; // Altitude offset stored during calibration 65 | u16 timeout; // Timeout 66 | }; 67 | extern struct baro sBaro; 68 | 69 | // ************************************************************************************************* 70 | // Extern section 71 | 72 | #endif /*ALTITUDE_H_ */ 73 | -------------------------------------------------------------------------------- /logic/acceleration.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef ACCELERATION_H_ 37 | #define ACCELERATION_H_ 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | 42 | // ************************************************************************************************* 43 | // Prototypes section 44 | 45 | // ************************************************************************************************* 46 | // Defines section 47 | #define DISPLAY_ACCEL_X (0u) 48 | #define DISPLAY_ACCEL_Y (1u) 49 | #define DISPLAY_ACCEL_Z (2u) 50 | 51 | #define ACCEL_MODE_OFF (0u) 52 | #define ACCEL_MODE_ON (1u) 53 | 54 | // Stop acceleration measurement after 60 minutes to save battery 55 | #define ACCEL_MEASUREMENT_TIMEOUT (60 * 60u) 56 | 57 | // ************************************************************************************************* 58 | // Global Variable section 59 | struct accel 60 | { 61 | u8 mode; // ACC_MODE_OFF, ACC_MODE_ON 62 | u8 xyz[3]; // Sensor raw data 63 | u16 data; // Acceleration data in 10 * mgrav 64 | u8 view_style; // Display X/Y/Z values 65 | u16 timeout; // Timeout 66 | }; 67 | extern struct accel sAccel; 68 | 69 | // ************************************************************************************************* 70 | // Extern section 71 | extern void reset_acceleration(void); 72 | extern void sx_acceleration(u8 line); 73 | extern void display_acceleration(u8 line, u8 update); 74 | extern u8 is_acceleration_measurement(void); 75 | extern void do_acceleration_measurement(void); 76 | 77 | #endif /*ACCELERATION_H_ */ 78 | -------------------------------------------------------------------------------- /logic/altitude.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef ALTITUDE_H_ 37 | #define ALTITUDE_H_ 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | 42 | // ************************************************************************************************* 43 | // Prototypes section 44 | extern void reset_altitude_measurement(void); 45 | extern u8 is_altitude_measurement(void); 46 | extern void start_altitude_measurement(void); 47 | extern void stop_altitude_measurement(void); 48 | extern void do_altitude_measurement(u8 filter); 49 | 50 | // menu functions 51 | extern void sx_altitude(u8 line); 52 | extern void mx_altitude(u8 line); 53 | extern void display_altitude(u8 line, u8 update); 54 | 55 | // ************************************************************************************************* 56 | // Defines section 57 | #define ALTITUDE_MEASUREMENT_TIMEOUT (60 * 60u) // Stop altitude measurement after 60 minutes to 58 | // save battery 59 | 60 | // ************************************************************************************************* 61 | // Global Variable section 62 | struct alt 63 | { 64 | menu_t state; // MENU_ITEM_NOT_VISIBLE, MENU_ITEM_VISIBLE 65 | u32 pressure; // Pressure (Pa) 66 | u16 temperature; // Temperature (K) 67 | s16 altitude; // Altitude (m) 68 | s16 altitude_offset; // Altitude offset stored during calibration 69 | u16 timeout; // Timeout 70 | }; 71 | extern struct alt sAlt; 72 | 73 | // ************************************************************************************************* 74 | // Extern section 75 | 76 | #endif /*ALTITUDE_H_ */ 77 | -------------------------------------------------------------------------------- /driver/buzzer.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef BUZZER_H_ 37 | #define BUZZER_H_ 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | 42 | // ************************************************************************************************* 43 | // Prototypes section 44 | extern void reset_buzzer(void); 45 | extern void start_buzzer(u8 cycles, u16 on_time, u16 off_time); 46 | extern void stop_buzzer(void); 47 | extern void toggle_buzzer(void); 48 | extern u8 is_buzzer(void); 49 | extern void countdown_buzzer(void); 50 | 51 | // ************************************************************************************************* 52 | // Defines section 53 | 54 | // Buzzer states 55 | #define BUZZER_OFF (0u) 56 | #define BUZZER_ON_OUTPUT_DISABLED (1u) 57 | #define BUZZER_ON_OUTPUT_ENABLED (2u) 58 | 59 | // Buzzer output signal frequency = 32,768kHz/(BUZZER_TIMER_STEPS+1)/2 = 2.7kHz 60 | #define BUZZER_TIMER_STEPS (5u) 61 | 62 | // Buzzer on time 63 | #define BUZZER_ON_TICKS (CONV_MS_TO_TICKS(20)) 64 | 65 | // Buzzer off time 66 | #define BUZZER_OFF_TICKS (CONV_MS_TO_TICKS(200)) 67 | 68 | // ************************************************************************************************* 69 | // Global Variable section 70 | struct buzzer 71 | { 72 | // Keep output for "time" seconds 73 | u8 time; 74 | 75 | // On/off duty 76 | u16 on_time; 77 | u16 off_time; 78 | 79 | // Current buzzer output state 80 | u8 state; 81 | }; 82 | extern struct buzzer sBuzzer; 83 | 84 | // ************************************************************************************************* 85 | // Extern section 86 | 87 | #endif /*BUZZER_H_ */ 88 | -------------------------------------------------------------------------------- /logic/stopwatch.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef STOPWATCH_H_ 37 | #define STOPWATCH_H_ 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | #include 42 | 43 | // ************************************************************************************************* 44 | // Prototypes section 45 | extern void start_stopwatch(void); 46 | extern void stop_stopwatch(void); 47 | extern void reset_stopwatch(void); 48 | extern u8 is_stopwatch(void); 49 | extern void stopwatch_tick(void); 50 | extern void update_stopwatch_timer(void); 51 | extern void mx_stopwatch(u8 line); 52 | extern void sx_stopwatch(u8 line); 53 | extern void display_stopwatch(u8 line, u8 update); 54 | 55 | // ************************************************************************************************* 56 | // Defines section 57 | #define STOPWATCH_1HZ_TICK (32768 / 1) 58 | #define STOPWATCH_100HZ_TICK (32768 / 100) 59 | #define STOPWATCH_STOP (0u) 60 | #define STOPWATCH_RUN (1u) 61 | #define STOPWATCH_HIDE (2u) 62 | 63 | // ************************************************************************************************* 64 | // Global Variable section 65 | struct stopwatch 66 | { 67 | u8 state; 68 | u8 drawFlag; 69 | u8 swtIs1Hz; 70 | u8 swtIs10Hz; 71 | 72 | u8 time[8]; // time[0] hour H 73 | // time[1] hour L 74 | // time[2] minute H 75 | // time[3] minute L 76 | // time[4] second H 77 | // time[5] second L 78 | // time[6] 1/10 sec 79 | // time[7] 1/100 sec 80 | 81 | // Display style 82 | u8 viewStyle; 83 | }; 84 | extern struct stopwatch sStopwatch; 85 | 86 | // ************************************************************************************************* 87 | // Extern section 88 | 89 | #endif /*STOPWATCH_H_ */ 90 | -------------------------------------------------------------------------------- /driver/bmp_as.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef BMP_AS_H_ 37 | #define BMP_AS_H_ 38 | 39 | 40 | // ************************************************************************************************* 41 | // Include section 42 | 43 | 44 | // ************************************************************************************************* 45 | // Prototypes section 46 | extern void bmp_as_start(void); 47 | extern void bmp_as_stop(void); 48 | extern u8 bmp_as_read_register(u8 bAddress); 49 | extern u8 bmp_as_write_register(u8 bAddress, u8 bData); 50 | extern void bmp_as_get_data(u8 * data); 51 | 52 | 53 | // ************************************************************************************************* 54 | // Defines section 55 | 56 | #define BMP_RSTKEY (0xB6) 57 | 58 | /******************************************************************** 59 | * 60 | * Bosch BMA250 61 | * Register Map 62 | * 63 | ********************************************************************/ 64 | 65 | #define BMP_CHIPID (0x00) 66 | #define BMP_ACC_X_LSB (0x02) 67 | #define BMP_ACC_X_MSB (0x03) 68 | #define BMP_ACC_Y_LSB (0x04) 69 | #define BMP_ACC_Y_MSB (0x05) 70 | #define BMP_ACC_Z_LSB (0x06) 71 | #define BMP_ACC_Z_MSB (0x07) 72 | 73 | #define BMP_GRANGE (0x0F) // g Range 74 | #define BMP_BWD (0x10) // Bandwidth 75 | #define BMP_PM (0x11) // Power modes 76 | #define BMP_SCR (0x13) // Special Control Register 77 | #define BMP_RESET (0x14) // Soft reset register (writing 0xB6 causes reset) 78 | #define BMP_ISR1 (0x16) // Interrupt settings register 1 79 | #define BMP_ISR2 (0x17) // Interrupt settings register 2 80 | #define BMP_IMR1 (0x19) // Interrupt mapping register 1 81 | #define BMP_IMR2 (0x1A) // Interrupt mapping register 2 82 | #define BMP_IMR3 (0x1B) // Interrupt mapping register 3 83 | 84 | // ************************************************************************************************* 85 | // Global Variable section 86 | 87 | 88 | // ************************************************************************************************* 89 | // Extern section 90 | 91 | 92 | #endif /*BMP_AS_H_*/ 93 | -------------------------------------------------------------------------------- /logic/menu.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef MENU_H_ 37 | #define MENU_H_ 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | 42 | // ************************************************************************************************* 43 | // Prototypes section 44 | 45 | // ************************************************************************************************* 46 | // Defines section 47 | 48 | struct menu 49 | { 50 | // Pointer to direct function (start, stop etc) 51 | void (*sx_function)(u8 line); 52 | // Pointer to sub menu function (change settings, reset counter etc) 53 | void (*mx_function)(u8 line); 54 | // Pointer to display function 55 | void (*display_function)(u8 line, u8 mode); 56 | // Display update trigger 57 | u8 (*display_update)(void); 58 | // Pointer to next menu item 59 | const struct menu *next; 60 | }; 61 | 62 | // ************************************************************************************************* 63 | // Global Variable section 64 | 65 | // ************************************************************************************************* 66 | // Extern section 67 | 68 | // Line1 navigation 69 | extern const struct menu menu_L1_Time; 70 | extern const struct menu menu_L1_Temperature; 71 | extern const struct menu menu_L1_Altitude; 72 | extern const struct menu menu_L1_Baro; 73 | extern const struct menu menu_L1_Alarm; 74 | // extern const struct menu menu_L1_Altitude; 75 | // extern const struct menu menu_L1_Heartrate; 76 | // extern const struct menu menu_L1_Speed; 77 | extern const struct menu menu_L1_Acceleration; 78 | 79 | // Line2 navigation 80 | extern const struct menu menu_L2_Date; 81 | extern const struct menu menu_L2_Stopwatch; 82 | extern const struct menu menu_L2_Battery; 83 | extern const struct menu menu_L2_RFAccel; 84 | extern const struct menu menu_L2_Ctrl; 85 | extern const struct menu menu_L2_Sync; 86 | // extern const struct menu menu_L2_CalDist; 87 | extern const struct menu menu_L2_RFBSL; 88 | 89 | // Pointers to current menu item 90 | extern const struct menu *ptrMenu_L1; 91 | extern const struct menu *ptrMenu_L2; 92 | 93 | #endif /*MENU_H_ */ 94 | -------------------------------------------------------------------------------- /driver/pmm.c: -------------------------------------------------------------------------------- 1 | //****************************************************************************// 2 | // Function Library for setting the PMM 3 | // 4 | // This file is used in conjunction with PMM.c to set the core 5 | // voltage level of a device. To set a core voltage level, call 6 | // SetVCore(level). See RF project(s) for example usage. 7 | // 8 | // Original programm Stefan Schauer 9 | // Rev 1.1: changed VCoreUp to fit with recommended flow (09/04/2008) 10 | // 11 | //****************************************************************************// 12 | #include "cc430x613x.h" 13 | #include "pmm.h" 14 | 15 | //****************************************************************************// 16 | // Set VCore level 17 | // SetVCore level is called from the user API 18 | //****************************************************************************// 19 | void SetVCore(unsigned char level) // Note: change level by one 20 | // step only 21 | { 22 | unsigned char actLevel; 23 | 24 | do 25 | { 26 | actLevel = PMMCTL0_L & PMMCOREV_3; 27 | if (actLevel < level) 28 | SetVCoreUp(++actLevel); // Set VCore (step by step) 29 | if (actLevel > level) 30 | SetVCoreDown(--actLevel); // Set VCore (step by step) 31 | } 32 | while (actLevel != level); 33 | } 34 | 35 | //****************************************************************************// 36 | // Set VCore up 37 | //****************************************************************************// 38 | void SetVCoreUp(unsigned char level) // Note: change level by one 39 | // step only 40 | { 41 | // Open PMM module registers for write access 42 | PMMCTL0_H = 0xA5; 43 | 44 | // Set SVS/M high side to new level 45 | SVSMHCTL = SVSHE + SVSHRVL0 * level + SVMHE + SVSMHRRL0 * level; 46 | 47 | SVSMLCTL = SVSLE + SVMLE + SVSMLRRL0 * level; // Set SVM new Level 48 | while ((PMMIFG & SVSMLDLYIFG) == 0) ; // Wait till SVM is settled 49 | // (Delay) 50 | PMMCTL0_L = PMMCOREV0 * level; // Set VCore to x 51 | PMMIFG &= ~(SVMLVLRIFG + SVMLIFG); // Clear already set flags 52 | if ((PMMIFG & SVMLIFG)) 53 | while ((PMMIFG & SVMLVLRIFG) == 0) ; // Wait till level is reached 54 | 55 | SVSMLCTL = SVSLE + SVSLRVL0 * level + SVMLE + SVSMLRRL0 * level; // Set SVS/M Low side to new 56 | // level 57 | PMMCTL0_H = 0x00; // Lock PMM module registers 58 | // for write access 59 | } 60 | 61 | //****************************************************************************// 62 | // Set VCore down 63 | //****************************************************************************// 64 | void SetVCoreDown(unsigned char level) 65 | { 66 | PMMCTL0_H = 0xA5; // Open PMM module registers 67 | // for write access 68 | SVSMLCTL = SVSLE + SVSLRVL0 * level + SVMLE + SVSMLRRL0 * level; // Set SVS/M Low side to new 69 | // level 70 | while ((PMMIFG & SVSMLDLYIFG) == 0) ; // Wait till SVM is settled 71 | // (Delay) 72 | PMMCTL0_L = (level * PMMCOREV0); // Set VCore to 1.85 V for Max 73 | // Speed. 74 | PMMCTL0_H = 0x00; // Lock PMM module registers 75 | // for write access 76 | } 77 | 78 | //****************************************************************************// 79 | -------------------------------------------------------------------------------- /logic/rfsimpliciti.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef RFSIMPLICITI_H_ 37 | #define RFSIMPLICITI_H_ 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | 42 | // ************************************************************************************************* 43 | // Prototypes section 44 | extern void reset_rf(void); 45 | extern void sx_rf(u8 line); 46 | extern void sx_ctrl(u8 line); 47 | extern void sx_sync(u8 line); 48 | extern void display_rf(u8 line, u8 update); 49 | extern void display_ctrl(u8 line, u8 update); 50 | extern void display_sync(u8 line, u8 update); 51 | extern void send_smpl_data(u16 data); 52 | extern u8 is_rf(void); 53 | 54 | // ************************************************************************************************* 55 | // Defines section 56 | 57 | // SimpliciTI connection states 58 | typedef enum 59 | { 60 | SIMPLICITI_OFF = 0, // Not connected 61 | SIMPLICITI_ACCELERATION, // Transmitting acceleration data and button events 62 | SIMPLICITI_BUTTONS, // Transmitting button events 63 | SIMPLICITI_SYNC // Syncing 64 | } simpliciti_mode_t; 65 | 66 | // Stop SimpliciTI transmission after 60 minutes to save power 67 | #define SIMPLICITI_TIMEOUT (60 * 60u) 68 | 69 | // Button flags for SimpliciTI data 70 | #define SIMPLICITI_BUTTON_STAR (0x10) 71 | #define SIMPLICITI_BUTTON_NUM (0x20) 72 | #define SIMPLICITI_BUTTON_UP (0x30) 73 | 74 | // SimpliciTI mode flag 75 | #define SIMPLICITI_MOUSE_EVENTS (0x01) 76 | #define SIMPLICITI_KEY_EVENTS (0x02) 77 | 78 | // ************************************************************************************************* 79 | // Global Variable section 80 | struct RFsmpl 81 | { 82 | // SIMPLICITI_OFF, SIMPLICITI_ACCELERATION, SIMPLICITI_BUTTONS 83 | simpliciti_mode_t mode; 84 | 85 | // Timeout until SimpliciTI transmission is automatically stopped 86 | u16 timeout; 87 | 88 | // Variable to display 89 | u8 display_sync_done; 90 | }; 91 | extern struct RFsmpl sRFsmpl; 92 | 93 | extern unsigned char simpliciti_flag; 94 | 95 | // ************************************************************************************************* 96 | // Extern section 97 | 98 | #endif /*RFSIMPLICITI_H_ */ 99 | -------------------------------------------------------------------------------- /driver/bmp_ps.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef BMP_PS_H_ 37 | #define BMP_PS_H_ 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | 42 | // ************************************************************************************************* 43 | // Prototypes section 44 | extern void bmp_ps_init(void); 45 | extern void bmp_ps_get_cal_param(void); 46 | extern void bmp_ps_start(void); 47 | extern void bmp_ps_stop(void); 48 | extern u16 bmp_ps_read_register(u8 address, u8 mode); 49 | extern u8 bmp_ps_write_register(u8 address, u8 data); 50 | extern u32 bmp_ps_get_pa(void); 51 | extern u16 bmp_ps_get_temp(void); 52 | 53 | // ************************************************************************************************* 54 | // Defines section 55 | 56 | // Bosch BMP085 defines 57 | 58 | #define BMP_085_CHIP_ID (0x55) 59 | #define BMP_085_I2C_ADDR (0xEE >> 1) 60 | 61 | #define BMP_085_PROM_START_ADDR (0xAA) 62 | #define BMP_085_CHIP_ID_REG (0xD0) 63 | #define BMP_085_VERSION_REG (0xD1) 64 | 65 | #define BMP_085_CTRL_MEAS_REG (0xF4) 66 | #define BMP_085_ADC_OUT_MSB_REG (0xF6) 67 | #define BMP_085_ADC_OUT_LSB_REG (0xF7) 68 | 69 | #define BMP_085_SOFT_RESET_REG (0xE0) 70 | 71 | #define BMP_085_T_MEASURE (0x2E) // temperature measurent 72 | #define BMP_085_P_MEASURE (0x34) // pressure measurement 73 | 74 | #define BMP_085_TEMP_CONVERSION_TIME (5) // TO be spec'd by GL or SB 75 | 76 | #define BMP_SMD500_PARAM_MG (3038) //calibration parameter 77 | #define BMP_SMD500_PARAM_MH (-7357) //calibration parameter 78 | #define BMP_SMD500_PARAM_MI (3791) //calibration parameter 79 | #define BMP_SMD500_PARAM_MJ (64385) //calibration parameter 80 | 81 | /** this structure holds all device specific calibration parameters 82 | */ 83 | typedef struct { 84 | short ac1; 85 | short ac2; 86 | short ac3; 87 | unsigned short ac4; 88 | unsigned short ac5; 89 | unsigned short ac6; 90 | short b1; 91 | short b2; 92 | short mb; 93 | short mc; 94 | short md; 95 | } bmp_085_calibration_param_t; 96 | 97 | // ************************************************************************************************* 98 | // Global Variable section 99 | 100 | 101 | // ************************************************************************************************* 102 | // Extern section 103 | 104 | #endif /*BMP_PS_H_ */ 105 | -------------------------------------------------------------------------------- /driver/as.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef AS_H_ 37 | #define AS_H_ 38 | 39 | 40 | // ************************************************************************************************* 41 | // Include section 42 | 43 | // ************************************************************************************************* 44 | // Prototypes section 45 | extern void as_init(void); 46 | extern void as_start(void); 47 | extern void as_stop(void); 48 | extern u8 as_read_register(u8 bAddress); 49 | extern u8 as_write_register(u8 bAddress, u8 bData); 50 | 51 | // ************************************************************************************************* 52 | // Defines section 53 | 54 | // Disconnect power supply for acceleration sensor when not used 55 | #define AS_DISCONNECT 56 | 57 | // Port and pin resource for SPI interface to acceleration sensor 58 | // SDO=MOSI=P1.6, SDI=MISO=P1.5, SCK=P1.7 59 | #define AS_SPI_IN (P1IN) 60 | #define AS_SPI_OUT (P1OUT) 61 | #define AS_SPI_DIR (P1DIR) 62 | #define AS_SPI_SEL (P1SEL) 63 | #define AS_SPI_REN (P1REN) 64 | #define AS_SDO_PIN (BIT6) 65 | #define AS_SDI_PIN (BIT5) 66 | #define AS_SCK_PIN (BIT7) 67 | 68 | // CSN=PJ.1 69 | #define AS_CSN_OUT (PJOUT) 70 | #define AS_CSN_DIR (PJDIR) 71 | #define AS_CSN_PIN (BIT1) 72 | 73 | #define AS_TX_BUFFER (UCA0TXBUF) 74 | #define AS_RX_BUFFER (UCA0RXBUF) 75 | #define AS_TX_IFG (UCTXIFG) 76 | #define AS_RX_IFG (UCRXIFG) 77 | #define AS_IRQ_REG (UCA0IFG) 78 | #define AS_SPI_CTL0 (UCA0CTL0) 79 | #define AS_SPI_CTL1 (UCA0CTL1) 80 | #define AS_SPI_BR0 (UCA0BR0) 81 | #define AS_SPI_BR1 (UCA0BR1) 82 | 83 | // Port and pin resource for power-up of acceleration sensor, VDD=PJ.0 84 | #define AS_PWR_OUT (PJOUT) 85 | #define AS_PWR_DIR (PJDIR) 86 | #define AS_PWR_PIN (BIT0) 87 | 88 | // Port, pin and interrupt resource for interrupt from acceleration sensor, CMA_INT=P2.5 89 | #define AS_INT_IN (P2IN) 90 | #define AS_INT_OUT (P2OUT) 91 | #define AS_INT_DIR (P2DIR) 92 | #define AS_INT_IE (P2IE) 93 | #define AS_INT_IES (P2IES) 94 | #define AS_INT_IFG (P2IFG) 95 | #define AS_INT_PIN (BIT5) 96 | 97 | // SPI timeout to detect sensor failure 98 | #define AS_SPI_TIMEOUT (1000u) 99 | 100 | // ************************************************************************************************* 101 | // Global Variable section 102 | 103 | 104 | // ************************************************************************************************* 105 | // Extern section 106 | 107 | // Global flag for proper acceleration sensor operation 108 | extern u8 as_ok; 109 | 110 | 111 | #endif /*AS_H_*/ 112 | -------------------------------------------------------------------------------- /driver/ps.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef PS_H_ 37 | #define PS_H_ 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | 42 | // ************************************************************************************************* 43 | // Prototypes section 44 | extern void ps_init(void); 45 | extern u8 ps_i2c_sda(u8 ack); 46 | extern void ps_i2c_delay(void); 47 | extern void ps_i2c_write(u8 data); 48 | extern u8 ps_i2c_read(u8 ack); 49 | extern u8 ps_write_register(u8 device, u8 address, u8 data); 50 | extern u16 ps_read_register(u8 device, u8 address, u8 mode); 51 | extern void init_pressure_table(void); 52 | extern void update_pressure_table(s16 href, u32 p_meas, u16 t_meas); 53 | extern s16 conv_pa_to_meter(u32 p_meas, u16 t_meas); 54 | 55 | // ************************************************************************************************* 56 | // Defines section 57 | 58 | // Port and pin resource for I2C interface to pressure sensor 59 | // SCL=PJ.3, SDA=PJ.2, EOC=P2.6 60 | #define PS_I2C_IN (PJIN) 61 | #define PS_I2C_OUT (PJOUT) 62 | #define PS_I2C_DIR (PJDIR) 63 | #define PS_I2C_REN (PJREN) 64 | #define PS_SCL_PIN (BIT3) 65 | #define PS_SDA_PIN (BIT2) 66 | 67 | // Port, pin and interrupt resource for interrupt from acceleration sensor, EOC=P2.6 68 | #define PS_INT_IN (P2IN) 69 | #define PS_INT_OUT (P2OUT) 70 | #define PS_INT_DIR (P2DIR) 71 | #define PS_INT_IE (P2IE) 72 | #define PS_INT_IES (P2IES) 73 | #define PS_INT_IFG (P2IFG) 74 | #define PS_INT_PIN (BIT6) 75 | 76 | // I2C defines 77 | #define PS_I2C_WRITE (0u) 78 | #define PS_I2C_READ (1u) 79 | 80 | #define PS_I2C_SEND_START (0u) 81 | #define PS_I2C_SEND_RESTART (1u) 82 | #define PS_I2C_SEND_STOP (2u) 83 | #define PS_I2C_CHECK_ACK (3u) 84 | 85 | #define PS_I2C_8BIT_ACCESS (0u) 86 | #define PS_I2C_16BIT_ACCESS (1u) 87 | 88 | #define PS_I2C_SCL_HI { PS_I2C_OUT |= PS_SCL_PIN; } 89 | #define PS_I2C_SCL_LO { PS_I2C_OUT &= ~PS_SCL_PIN; } 90 | #define PS_I2C_SDA_HI { PS_I2C_OUT |= PS_SDA_PIN; } 91 | #define PS_I2C_SDA_LO { PS_I2C_OUT &= ~PS_SDA_PIN; } 92 | #define PS_I2C_SDA_IN { PS_I2C_OUT |= PS_SDA_PIN; PS_I2C_DIR &= ~PS_SDA_PIN; } 93 | #define PS_I2C_SDA_OUT { PS_I2C_DIR |= PS_SDA_PIN; } 94 | 95 | // ************************************************************************************************* 96 | // Global Variable section 97 | 98 | // ************************************************************************************************* 99 | // Extern section 100 | 101 | // Global flag for pressure sensor initialisation status 102 | extern u8 ps_ok; 103 | 104 | 105 | #endif /*PS_H_ */ 106 | -------------------------------------------------------------------------------- /logic/rfbsl.c: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | // Wireless Update functions. 36 | // ************************************************************************************************* 37 | 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | 42 | // system 43 | #include "project.h" 44 | 45 | // driver 46 | #include "display.h" 47 | #include "ports.h" 48 | 49 | // logic 50 | #include "rfbsl.h" 51 | #include "bluerobin.h" 52 | #include "rfsimpliciti.h" 53 | 54 | // ************************************************************************************************* 55 | // Global Variable section 56 | u8 rfBSL_button_confirmation; 57 | 58 | // ************************************************************************************************* 59 | // @fn sx_rfbsl 60 | // @brief This functions starts the RFBSL 61 | // @param line LINE1, LINE2 62 | // @return none 63 | // ************************************************************************************************* 64 | void sx_rfbsl(u8 line) 65 | { 66 | // Exit if battery voltage is too low for radio operation 67 | if (sys.flag.low_battery) 68 | return; 69 | 70 | // Exit if BlueRobin stack is active 71 | if (is_bluerobin()) 72 | return; 73 | 74 | // Exit if SimpliciTI stack is active 75 | if (is_rf()) 76 | return; 77 | 78 | rfBSL_button_confirmation++; 79 | 80 | if (rfBSL_button_confirmation == 2) 81 | { 82 | // Before entering RFBSL clear the LINE1 Symbols 83 | display_symbol(LCD_SYMB_AM, SEG_OFF); 84 | 85 | clear_line(LINE1); 86 | 87 | // Write RAM to indicate we will be downloading the RAM Updater first 88 | display_chars(LCD_SEG_L2_5_0, (u8 *) " RFBSL", SEG_ON); 89 | display_chars(LCD_SEG_L1_3_0, (u8 *) " RAM", SEG_ON); 90 | 91 | // Call RFBSL 92 | CALL_RFSBL(); 93 | } 94 | } 95 | 96 | // ************************************************************************************************* 97 | // @fn display_rfbsl 98 | // @brief RFBSL display routine. 99 | // @param u8 line LINE2 100 | // u8 update DISPLAY_LINE_UPDATE_FULL 101 | // @return none 102 | // ************************************************************************************************* 103 | void display_rfbsl(u8 line, u8 update) 104 | { 105 | if (update == DISPLAY_LINE_UPDATE_FULL) 106 | { 107 | if (rfBSL_button_confirmation == 0) 108 | { 109 | display_chars(LCD_SEG_L2_5_0, (u8 *) " RFBSL", SEG_ON); 110 | } 111 | else if (rfBSL_button_confirmation < 2) 112 | { 113 | // Request one more button press to confirm rfBSL call 114 | display_chars(LCD_SEG_L2_5_0, (u8 *) " CONF", SEG_ON); 115 | } 116 | } 117 | } 118 | 119 | -------------------------------------------------------------------------------- /logic/bluerobin.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef BLUEROBIN_H_ 37 | #define BLUEROBIN_H_ 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | #include 42 | 43 | // ************************************************************************************************* 44 | // Prototypes section 45 | extern void reset_bluerobin(void); 46 | extern void mx_bluerobin(u8 line); 47 | extern void sx_bluerobin(u8 line); 48 | extern void mx_caldist(u8 line); 49 | extern void display_heartrate(u8 line, u8 update); 50 | extern void display_speed(u8 line, u8 update); 51 | extern void sx_caldist(u8 line); 52 | extern void mx_caldist(u8 line); 53 | extern void display_caldist(u8 line, u8 update); 54 | extern u8 is_bluerobin(void); 55 | extern u8 is_bluerobin_searching(void); 56 | extern void get_bluerobin_data(void); 57 | extern void stop_bluerobin(void); 58 | 59 | // ************************************************************************************************* 60 | // Defines section 61 | 62 | // BlueRobin connection states 63 | typedef enum 64 | { 65 | BLUEROBIN_OFF = 0, // Not connected 66 | BLUEROBIN_SEARCHING, // Searching for transmitter 67 | BLUEROBIN_CONNECTED, // Connected 68 | BLUEROBIN_ERROR // Error occurred while trying to connect or while connected 69 | } BlueRobin_state_t; 70 | 71 | // BlueRobin data update states 72 | typedef enum 73 | { 74 | BLUEROBIN_NO_UPDATE = 0, // No new data available 75 | BLUEROBIN_NEW_DATA // New data arrived 76 | } BlueRobin_update_t; 77 | 78 | #define USER_SEX_MALE 0 79 | #define USER_SEX_FEMALE 1 80 | #define USER_WEIGHT_MIN_KG 30 81 | #define USER_WEIGHT_MAX_KG 150 82 | #define USER_WEIGHT_MIN_LB 70 83 | #define USER_WEIGHT_MAX_LB 400 84 | 85 | // ************************************************************************************************* 86 | // Global Variable section 87 | struct bluerobin 88 | { 89 | BlueRobin_state_t state; // BLUEROBIN_OFF, BLUEROBIN_SEARCHING, BLUEROBIN_CONNECTED, 90 | // BLUEROBIN_ERROR 91 | BlueRobin_update_t update; // BLUEROBIN_NO_UPDATE, BLUEROBIN_NEW_DATA 92 | u32 cs_id; // Chest strap ID 93 | u8 user_sex; // User settings 94 | u16 user_weight; 95 | u8 heartrate; // Heart rate (1 bpm) 96 | u32 calories; // Calories (1 kCal) - calculated from heart rate, user weight and 97 | // user sex 98 | u8 speed; // Speed (0.1 km/h) - demo version range is 0.0 to 25.5km/h 99 | u32 distance; // Distance (1 m) 100 | u8 caldist_view; // 0=display calories, 1=display distance 101 | }; 102 | extern struct bluerobin sBlueRobin; 103 | 104 | // ************************************************************************************************* 105 | // Extern section 106 | 107 | #endif /*BLUEROBIN_H_ */ 108 | -------------------------------------------------------------------------------- /include/project.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef PROJECT_H_ 37 | #define PROJECT_H_ 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | #include 42 | #include 43 | 44 | // ************************************************************************************************* 45 | // Defines section 46 | 47 | // Comment this to not use the LCD charge pump 48 | //#define USE_LCD_CHARGE_PUMP 49 | 50 | // Comment this define to build the application without watchdog support 51 | //#define USE_WATCHDOG 52 | 53 | // Use/not use filter when measuring physical values 54 | #define FILTER_OFF (0u) 55 | #define FILTER_ON (1u) 56 | 57 | // ************************************************************************************************* 58 | // Macro section 59 | 60 | // Conversion from usec to ACLK timer ticks 61 | #define CONV_US_TO_TICKS(usec) (((usec) * 32768) / 1000000) 62 | 63 | // Conversion from msec to ACLK timer ticks 64 | #define CONV_MS_TO_TICKS(msec) (((msec) * 32768) / 1000) 65 | 66 | // ************************************************************************************************* 67 | // Typedef section 68 | 69 | typedef enum 70 | { 71 | MENU_ITEM_NOT_VISIBLE = 0, // Menu item is not visible 72 | MENU_ITEM_VISIBLE // Menu item is visible 73 | } menu_t; 74 | 75 | // Set of system flags 76 | typedef union 77 | { 78 | struct 79 | { 80 | u16 idle_timeout : 1; // Timeout after inactivity 81 | u16 idle_timeout_enabled : 1; // When in set mode, timeout after a given period 82 | u16 lock_buttons : 1; // Lock buttons 83 | u16 mask_buzzer : 1; // Do not output buzz for next button event 84 | u16 up_down_repeat_enabled : 1; // While in set_value(), create virtual UP/DOWN button 85 | // events 86 | u16 low_battery : 1; // 1 = Battery is low 87 | u16 use_metric_units : 1; // 1 = Use metric units, 0 = use English units 88 | u16 delay_over : 1; // 1 = Timer delay over 89 | } flag; 90 | u16 all_flags; // Shortcut to all system flags (for reset) 91 | } s_system_flags; 92 | extern volatile s_system_flags sys; 93 | 94 | // Set of request flags 95 | typedef union 96 | { 97 | struct 98 | { 99 | u16 temperature_measurement : 1; // 1 = Measure temperature 100 | u16 voltage_measurement : 1; // 1 = Measure voltage 101 | u16 altitude_measurement : 1; // 1 = Measure air pressure 102 | u16 acceleration_measurement : 1; // 1 = Measure acceleration 103 | u16 buzzer : 1; // 1 = Output buzzer 104 | } flag; 105 | u16 all_flags; // Shortcut to all request flags (for reset) 106 | } s_request_flags; 107 | extern volatile s_request_flags request; 108 | 109 | // Set of message flags 110 | typedef union 111 | { 112 | struct 113 | { 114 | u16 prepare : 1; // 1 = Wait for clock tick, then set 115 | // display.flag.show_message flag 116 | u16 show : 1; // 1 = Display message now 117 | u16 erase : 1; // 1 = Erase message 118 | u16 type_locked : 1; // 1 = Show "buttons are locked" in Line2 119 | u16 type_unlocked : 1; // 1 = Show "buttons are unlocked" in Line2 120 | u16 type_lobatt : 1; // 1 = Show "lobatt" text in Line2 121 | u16 type_alarm_on : 1; // 1 = Show " on" text in Line1 122 | u16 type_alarm_off : 1; // 1 = Show " off" text in Line1 123 | } flag; 124 | u16 all_flags; // Shortcut to all message flags (for reset) 125 | } s_message_flags; 126 | extern volatile s_message_flags message; 127 | 128 | // ************************************************************************************************* 129 | // Global Variable section 130 | 131 | // Global flag set if Bosch sensors are used 132 | extern u8 bmp_used; 133 | 134 | #endif /*PROJECT_H_ */ 135 | -------------------------------------------------------------------------------- /driver/ports.h: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | 36 | #ifndef PORTS_H_ 37 | #define PORTS_H_ 38 | 39 | // ************************************************************************************************* 40 | // Defines section 41 | 42 | // Port, pins and interrupt resources for buttons 43 | #define BUTTONS_IN (P2IN) 44 | #define BUTTONS_OUT (P2OUT) 45 | #define BUTTONS_DIR (P2DIR) 46 | #define BUTTONS_REN (P2REN) 47 | #define BUTTONS_IE (P2IE) 48 | #define BUTTONS_IES (P2IES) 49 | #define BUTTONS_IFG (P2IFG) 50 | #define BUTTONS_IRQ_VECT2 (PORT2_VECTOR) 51 | 52 | // Button ports 53 | #define BUTTON_STAR_PIN (BIT2) 54 | #define BUTTON_NUM_PIN (BIT1) 55 | #define BUTTON_UP_PIN (BIT4) 56 | #define BUTTON_DOWN_PIN (BIT0) 57 | #define BUTTON_BACKLIGHT_PIN (BIT3) 58 | #define ALL_BUTTONS (BUTTON_STAR_PIN + BUTTON_NUM_PIN + BUTTON_UP_PIN + \ 59 | BUTTON_DOWN_PIN + BUTTON_BACKLIGHT_PIN) 60 | 61 | // Macros for button press detection 62 | #define BUTTON_STAR_IS_PRESSED ((BUTTONS_IN & BUTTON_STAR_PIN) == BUTTON_STAR_PIN) 63 | #define BUTTON_NUM_IS_PRESSED ((BUTTONS_IN & BUTTON_NUM_PIN) == BUTTON_NUM_PIN) 64 | #define BUTTON_UP_IS_PRESSED ((BUTTONS_IN & BUTTON_UP_PIN) == BUTTON_UP_PIN) 65 | #define BUTTON_DOWN_IS_PRESSED ((BUTTONS_IN & BUTTON_DOWN_PIN) == BUTTON_DOWN_PIN) 66 | #define BUTTON_BACKLIGHT_IS_PRESSED ((BUTTONS_IN & BUTTON_BACKLIGHT_PIN) == \ 67 | BUTTON_BACKLIGHT_PIN) 68 | #define NO_BUTTON_IS_PRESSED ((BUTTONS_IN & ALL_BUTTONS) == 0) 69 | 70 | // Macros for button release detection 71 | #define BUTTON_STAR_IS_RELEASED ((BUTTONS_IN & BUTTON_STAR_PIN) == 0) 72 | #define BUTTON_NUM_IS_RELEASED ((BUTTONS_IN & BUTTON_NUM_PIN) == 0) 73 | #define BUTTON_UP_IS_RELEASED (BUTTONS_IN & BUTTON_UP_PIN) == 0) 74 | #define BUTTON_DOWN_IS_RELEASED ((BUTTONS_IN & BUTTON_DOWN_PIN) == 0) 75 | #define BUTTON_BACKLIGHT_IS_RELEASED ((BUTTONS_IN & BUTTON_BACKLIGHT_PIN) == 0) 76 | 77 | // Button debounce time (msec) 78 | #define BUTTONS_DEBOUNCE_TIME_IN (5u) 79 | #define BUTTONS_DEBOUNCE_TIME_OUT (250u) 80 | #define BUTTONS_DEBOUNCE_TIME_LEFT (50u) 81 | 82 | // Detect if STAR / NUM button is held low continuously 83 | #define LEFT_BUTTON_LONG_TIME (2u) 84 | 85 | // Backlight time (sec) 86 | #define BACKLIGHT_TIME_ON (3u) 87 | 88 | // Leave set_value() function after some seconds of user inactivity 89 | #define INACTIVITY_TIME (30u) 90 | 91 | // Set of button flags 92 | typedef union 93 | { 94 | struct 95 | { 96 | // Manual button events 97 | u16 star : 1; // Short STAR button press 98 | u16 num : 1; // Short NUM button press 99 | u16 up : 1; // Short UP button press 100 | u16 down : 1; // Short DOWN button press 101 | u16 backlight : 1; // Short BACKLIGHT button press 102 | u16 star_long : 1; // Long STAR button press 103 | u16 num_long : 1; // Long NUM button press 104 | u16 star_not_long : 1; // Between short and long STAR button press 105 | u16 num_not_long : 1; // Between short and long NUM button press 106 | } flag; 107 | u16 all_flags; // Shortcut to all display flags (for reset) 108 | } s_button_flags; 109 | extern volatile s_button_flags button; 110 | 111 | struct struct_button 112 | { 113 | u8 star_timeout; // this variable is incremented each second if STAR button is still 114 | // pressed 115 | u8 num_timeout; // this variable is incremented each second if NUM button is still 116 | // pressed 117 | u8 backlight_timeout; // controls the timeout for the backlight 118 | u8 backlight_status; // 1 case backlight is on 119 | s16 repeats; 120 | }; 121 | extern volatile struct struct_button sButton; 122 | 123 | // ************************************************************************************************* 124 | // Extern section 125 | extern void button_repeat_on(u16 msec); 126 | extern void button_repeat_off(void); 127 | extern void button_repeat_function(void); 128 | extern void init_buttons(void); 129 | 130 | #endif /*PORTS_H_ */ 131 | -------------------------------------------------------------------------------- /logic/baro.c: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // Include section 3 | 4 | // system 5 | #include "project.h" 6 | 7 | // driver 8 | #include "baro.h" 9 | #include "display.h" 10 | #include "display.h" 11 | #include "ps.h" 12 | #include "bmp_ps.h" 13 | #include "cma_ps.h" 14 | #include "ports.h" 15 | #include "timer.h" 16 | 17 | // logic 18 | #include "user.h" 19 | 20 | // ************************************************************************************************* 21 | // Defines section 22 | 23 | // ************************************************************************************************* 24 | // Global Variable section 25 | struct baro sBaro; 26 | 27 | // ************************************************************************************************* 28 | // Extern section 29 | 30 | 31 | 32 | // ************************************************************************************************* 33 | // @fn is_barometer_measurement 34 | // @brief Altitude measurement check 35 | // @param none 36 | // @return u8 1=Measurement ongoing, 0=measurement off 37 | // ************************************************************************************************* 38 | u8 is_barometer_measurement(void) 39 | { 40 | return ((sBaro.state == MENU_ITEM_VISIBLE) && (sBaro.timeout > 0)); 41 | } 42 | 43 | // ************************************************************************************************* 44 | // @fn start_barometer_measurement 45 | // @brief Start barometer measurement 46 | // @param none 47 | // @return none 48 | // ************************************************************************************************* 49 | void start_barometer_measurement(void) 50 | { 51 | // Show warning if pressure sensor was not initialised properly 52 | if (!ps_ok) 53 | { 54 | display_chars(LCD_SEG_L1_2_0, (u8 *) "ERR", SEG_ON); 55 | return; 56 | } 57 | 58 | // Start barometer measurement if timeout has elapsed 59 | if (sBaro.timeout == 0) 60 | { 61 | // Enable EOC IRQ on rising edge 62 | PS_INT_IFG &= ~PS_INT_PIN; 63 | PS_INT_IE |= PS_INT_PIN; 64 | 65 | // Start pressure sensor 66 | if (bmp_used) 67 | { 68 | bmp_ps_start(); 69 | } 70 | else 71 | { 72 | cma_ps_start(); 73 | } 74 | 75 | // Set timeout counter only if sensor status was OK 76 | sBaro.timeout = BAROMETER_MEASUREMENT_TIMEOUT; 77 | 78 | // Get updated barometer 79 | while ((PS_INT_IN & PS_INT_PIN) == 0) ; 80 | do_barometer_measurement(FILTER_OFF); 81 | } 82 | } 83 | 84 | // ************************************************************************************************* 85 | // @fn stop_barometer_measurement 86 | // @brief Stop barometer measurement 87 | // @param none 88 | // @return none 89 | // ************************************************************************************************* 90 | void stop_barometer_measurement(void) 91 | { 92 | // Return if pressure sensor was not initialised properly 93 | if (!ps_ok) 94 | return; 95 | 96 | // Stop pressure sensor 97 | if (bmp_used) 98 | { 99 | bmp_ps_stop(); 100 | } 101 | else 102 | { 103 | cma_ps_stop(); 104 | } 105 | 106 | // Disable DRDY IRQ 107 | PS_INT_IE &= ~PS_INT_PIN; 108 | PS_INT_IFG &= ~PS_INT_PIN; 109 | 110 | // Clear timeout counter 111 | sBaro.timeout = 0; 112 | } 113 | 114 | // ************************************************************************************************* 115 | // @fn do_barometer_measurement 116 | // @brief Perform single barometer measurement 117 | // @param u8 filter Filter option 118 | // @return none 119 | // ************************************************************************************************* 120 | void do_barometer_measurement(u8 filter) 121 | { 122 | volatile u32 pressure; 123 | 124 | // If sensor is not ready, skip data read 125 | if ((PS_INT_IN & PS_INT_PIN) == 0) 126 | return; 127 | 128 | // Get pressure (format is 1Pa) from sensor 129 | if (bmp_used) 130 | { 131 | // Start sampling data in ultra low power mode 132 | bmp_ps_write_register(BMP_085_CTRL_MEAS_REG, BMP_085_P_MEASURE); 133 | // Get updated barometer 134 | while ((PS_INT_IN & PS_INT_PIN) == 0) ; 135 | 136 | pressure = bmp_ps_get_pa(); 137 | } 138 | else 139 | { 140 | pressure = cma_ps_get_pa(); 141 | } 142 | 143 | sBaro.pressure = pressure * 0.01; 144 | } 145 | 146 | 147 | // ************************************************************************************************* 148 | // @fn display_barometer 149 | // @brief Display routine. Supports display in meters and feet. 150 | // @param u8 line LINE1 151 | // u8 update DISPLAY_LINE_UPDATE_FULL, 152 | // DISPLAY_LINE_UPDATE_PARTIAL, DISPLAY_LINE_CLEAR 153 | // @return none 154 | // ************************************************************************************************* 155 | void display_barometer(u8 line, u8 update) 156 | { 157 | u8 *str; 158 | 159 | // redraw whole screen 160 | if (update == DISPLAY_LINE_UPDATE_FULL) 161 | { 162 | // Enable pressure measurement 163 | sBaro.state = MENU_ITEM_VISIBLE; 164 | 165 | // Start measurement 166 | start_barometer_measurement(); 167 | 168 | display_symbol(LCD_UNIT_L1_M, SEG_OFF); 169 | display_symbol(LCD_UNIT_L1_FT, SEG_OFF); 170 | // Display barometer 171 | display_barometer(LINE1, DISPLAY_LINE_UPDATE_PARTIAL); 172 | } 173 | else if (update == DISPLAY_LINE_UPDATE_PARTIAL) 174 | { 175 | // Update display only while measurement is active 176 | // if (sBaro.timeout > 0) 177 | // { 178 | // Display barometer in xxxx m format, allow 3 leading blank digits 179 | str = int_to_array(sBaro.pressure, 4, 3); 180 | display_symbol(LCD_SYMB_ARROW_UP, SEG_OFF); 181 | display_symbol(LCD_SYMB_ARROW_DOWN, SEG_OFF); 182 | display_chars(LCD_SEG_L1_3_0, str, SEG_ON); 183 | // } 184 | } 185 | else if (update == DISPLAY_LINE_CLEAR) 186 | { 187 | // Disable pressure measurement 188 | sBaro.state = MENU_ITEM_NOT_VISIBLE; 189 | 190 | // Stop measurement 191 | stop_barometer_measurement(); 192 | 193 | // Clean up function-specific segments before leaving function 194 | display_symbol(LCD_UNIT_L1_M, SEG_OFF); 195 | display_symbol(LCD_UNIT_L1_FT, SEG_OFF); 196 | display_symbol(LCD_SYMB_ARROW_UP, SEG_OFF); 197 | display_symbol(LCD_SYMB_ARROW_DOWN, SEG_OFF); 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /driver/adc12.c: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | // ADC12 functions. 36 | // ************************************************************************************************* 37 | 38 | // ************************************************************************************************* 39 | // Include section 40 | 41 | // system 42 | #include 43 | 44 | // driver 45 | #include "adc12.h" 46 | #include "timer.h" 47 | 48 | // ************************************************************************************************* 49 | // Prototypes section 50 | 51 | // ************************************************************************************************* 52 | // Defines section 53 | 54 | // ************************************************************************************************* 55 | // Global Variable section 56 | u16 adc12_result; 57 | u8 adc12_data_ready; 58 | 59 | // ************************************************************************************************* 60 | // Extern section 61 | 62 | // ************************************************************************************************* 63 | // @fn adc12_single_conversion 64 | // @brief Init ADC12. Do single conversion. Turn off ADC12. 65 | // @param u16 ref Select reference 66 | // u16 sht Sample-and-hold time 67 | // u16 channel Channel of the conversion 68 | // @return u16 adc12_result Return ADC result 69 | // ************************************************************************************************* 70 | u16 adc12_single_conversion(u16 ref, u16 sht, u16 channel) 71 | { 72 | // Initialize the shared reference module 73 | REFCTL0 |= REFMSTR + ref + REFON; // Enable internal reference (1.5V or 2.5V) 74 | 75 | // Initialize ADC12_A 76 | ADC12CTL0 = sht + ADC12ON; // Set sample time 77 | ADC12CTL1 = ADC12SHP; // Enable sample timer 78 | ADC12MCTL0 = ADC12SREF_1 + channel; // ADC input channel 79 | ADC12IE = 0x001; // ADC_IFG upon conv result-ADCMEMO 80 | 81 | // Wait 2 ticks (66us) to allow internal reference to settle 82 | Timer0_A4_Delay(2); 83 | 84 | // Start ADC12 85 | ADC12CTL0 |= ADC12ENC; 86 | 87 | // Clear data ready flag 88 | adc12_data_ready = 0; 89 | 90 | // Sampling and conversion start 91 | ADC12CTL0 |= ADC12SC; 92 | 93 | // Delay to get next ADC value 94 | Timer0_A4_Delay(5); 95 | while (!adc12_data_ready) ; 96 | 97 | // Shut down ADC12 98 | ADC12CTL0 &= ~(ADC12ENC | ADC12SC | sht); 99 | ADC12CTL0 &= ~ADC12ON; 100 | 101 | // Shut down reference voltage 102 | REFCTL0 &= ~(REFMSTR + ref + REFON); 103 | 104 | ADC12IE = 0; 105 | 106 | // Return ADC result 107 | return (adc12_result); 108 | } 109 | 110 | // ************************************************************************************************* 111 | // @fn ADC12ISR 112 | // @brief Store ADC12 conversion result. Set flag to indicate data ready. 113 | // @param none 114 | // @return none 115 | // ************************************************************************************************* 116 | #pragma vector=ADC12_VECTOR 117 | __interrupt void ADC12ISR(void) 118 | { 119 | switch (__even_in_range(ADC12IV, 34)) 120 | { 121 | case 0: 122 | break; // Vector 0: No interrupt 123 | case 2: 124 | break; // Vector 2: ADC overflow 125 | case 4: 126 | break; // Vector 4: ADC timing overflow 127 | case 6: // Vector 6: ADC12IFG0 128 | adc12_result = ADC12MEM0; // Move results, IFG is cleared 129 | adc12_data_ready = 1; 130 | _BIC_SR_IRQ(LPM3_bits); // Exit active CPU 131 | break; 132 | case 8: 133 | break; // Vector 8: ADC12IFG1 134 | case 10: 135 | break; // Vector 10: ADC12IFG2 136 | case 12: 137 | break; // Vector 12: ADC12IFG3 138 | case 14: 139 | break; // Vector 14: ADC12IFG4 140 | case 16: 141 | break; // Vector 16: ADC12IFG5 142 | case 18: 143 | break; // Vector 18: ADC12IFG6 144 | case 20: 145 | break; // Vector 20: ADC12IFG7 146 | case 22: 147 | break; // Vector 22: ADC12IFG8 148 | case 24: 149 | break; // Vector 24: ADC12IFG9 150 | case 26: 151 | break; // Vector 26: ADC12IFG10 152 | case 28: 153 | break; // Vector 28: ADC12IFG11 154 | case 30: 155 | break; // Vector 30: ADC12IFG12 156 | case 32: 157 | break; // Vector 32: ADC12IFG13 158 | case 34: 159 | break; // Vector 34: ADC12IFG14 160 | default: 161 | break; 162 | } 163 | } 164 | 165 | -------------------------------------------------------------------------------- /driver/radio.c: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | // Radio core access functions. Taken from TI reference code for CC430. 36 | // ************************************************************************************************* 37 | 38 | // system 39 | #include "project.h" 40 | 41 | // driver 42 | #include "rf1a.h" 43 | #include "timer.h" 44 | 45 | // logic 46 | #include "rfsimpliciti.h" 47 | #include "bluerobin.h" 48 | 49 | // ************************************************************************************************* 50 | // Extern section 51 | 52 | // SimpliciTI CC430 radio ISR - located in SimpliciTi library 53 | extern void MRFI_RadioIsr(void); 54 | 55 | // BlueRobin CC430 radio ISR - located in BlueRobin library 56 | extern void BlueRobin_RadioISR_v(void); 57 | 58 | // ************************************************************************************************* 59 | // @fn radio_reset 60 | // @brief Reset radio core. 61 | // @param none 62 | // @return none 63 | // ************************************************************************************************* 64 | void radio_reset(void) 65 | { 66 | volatile u16 i; 67 | u8 x; 68 | 69 | // Reset radio core 70 | Strobe(RF_SRES); 71 | // Wait before checking IDLE 72 | for (i = 0; i < 100; i++) ; 73 | do 74 | { 75 | x = Strobe(RF_SIDLE); 76 | } 77 | while ((x & 0x70) != 0x00); 78 | 79 | // Clear radio error register 80 | RF1AIFERR = 0; 81 | } 82 | 83 | // ************************************************************************************************* 84 | // @fn radio_powerdown 85 | // @brief Put radio to SLEEP mode. 86 | // @param none 87 | // @return none 88 | // ************************************************************************************************* 89 | void radio_powerdown(void) 90 | { 91 | // Chip bug: Radio does not come out of this SLEEP when put to sleep 92 | // using the SPWD cmd. However, it does wakes up if SXOFF was used to 93 | // put it to sleep. 94 | 95 | // Powerdown radio 96 | Strobe(RF_SIDLE); 97 | Strobe(RF_SPWD); 98 | } 99 | 100 | // ************************************************************************************************* 101 | // @fn radio_sxoff 102 | // @brief Put radio to SLEEP mode (XTAL off only). 103 | // @param none 104 | // @return none 105 | // ************************************************************************************************* 106 | void radio_sxoff(void) 107 | { 108 | // Chip bug: Radio does not come out of this SLEEP when put to sleep 109 | // using the SPWD cmd. However, it does wakes up if SXOFF was used to 110 | // put it to sleep. 111 | 112 | // Powerdown radio 113 | Strobe(RF_SIDLE); 114 | Strobe(RF_SXOFF); 115 | } 116 | 117 | // ************************************************************************************************* 118 | // @fn open_radio 119 | // @brief Prepare radio for RF communication. 120 | // @param none 121 | // @return none 122 | // ************************************************************************************************* 123 | void open_radio(void) 124 | { 125 | // Reset radio core 126 | radio_reset(); 127 | 128 | // Enable radio IRQ 129 | RF1AIFG &= ~BIT4; // Clear a pending interrupt 130 | RF1AIE |= BIT4; // Enable the interrupt 131 | } 132 | 133 | // ************************************************************************************************* 134 | // @fn close_radio 135 | // @brief Shutdown radio for RF communication. 136 | // @param none 137 | // @return none 138 | // ************************************************************************************************* 139 | void close_radio(void) 140 | { 141 | // Disable radio IRQ 142 | RF1AIFG = 0; 143 | RF1AIE = 0; 144 | 145 | // Reset radio core 146 | radio_reset(); 147 | 148 | // Put radio to sleep 149 | radio_powerdown(); 150 | } 151 | 152 | // ************************************************************************************************* 153 | // @fn GDOx_ISR 154 | // @brief GDO0/2 ISR to detect received packet. 155 | // In BlueRobin mode: capture packet end time and decode received 156 | // packet 157 | // In SimpliciTI mode: go to SimpliciTI handler 158 | // @param none 159 | // @return none 160 | // ************************************************************************************************* 161 | #pragma vector=CC1101_VECTOR 162 | __interrupt void radio_ISR(void) 163 | { 164 | u8 rf1aivec = RF1AIV; 165 | 166 | // Forward to SimpliciTI interrupt service routine 167 | if (is_rf()) 168 | { 169 | MRFI_RadioIsr(); 170 | } 171 | else // BlueRobin packet end interrupt service routine 172 | { 173 | if (rf1aivec == RF1AIV_RFIFG9) 174 | { 175 | if ((sBlueRobin.state == BLUEROBIN_SEARCHING) || 176 | (sBlueRobin.state == BLUEROBIN_CONNECTED)) 177 | { 178 | BlueRobin_RadioISR_v(); 179 | } 180 | } 181 | else if (rf1aivec == RF1AIV_NONE) // RF1A interface interrupt (error etc.) 182 | { 183 | asm (" nop"); // break here 184 | } 185 | } 186 | } 187 | 188 | -------------------------------------------------------------------------------- /logic/battery.c: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | // Battery voltage measurement functions. 36 | // ************************************************************************************************* 37 | 38 | // ************************************************************************************************* 39 | // Include section 40 | 41 | // system 42 | #include "project.h" 43 | 44 | // driver 45 | #include "display.h" 46 | #include "ports.h" 47 | #include "adc12.h" 48 | 49 | // logic 50 | #include "menu.h" 51 | #include "battery.h" 52 | 53 | // ************************************************************************************************* 54 | // Prototypes section 55 | void reset_batt_measurement(void); 56 | void battery_measurement(void); 57 | 58 | // ************************************************************************************************* 59 | // Defines section 60 | 61 | // ************************************************************************************************* 62 | // Global Variable section 63 | struct batt sBatt; 64 | 65 | // ************************************************************************************************* 66 | // Extern section 67 | extern void (*fptr_lcd_function_line2)(u8 line, u8 update); 68 | 69 | // ************************************************************************************************* 70 | // @fn reset_temp_measurement 71 | // @brief Reset temperature measurement module. 72 | // @param none 73 | // @return none 74 | // ************************************************************************************************* 75 | void reset_batt_measurement(void) 76 | { 77 | // Set flag to off 78 | sBatt.state = MENU_ITEM_NOT_VISIBLE; 79 | 80 | // Reset lobatt display counter 81 | sBatt.lobatt_display = BATTERY_LOW_MESSAGE_CYCLE; 82 | 83 | // Start with battery voltage of 3.00V 84 | sBatt.voltage = 300; 85 | } 86 | 87 | // ************************************************************************************************* 88 | // @fn battery_measurement 89 | // @brief Init ADC12. Do single conversion of AVCC voltage. Turn off ADC12. 90 | // @param none 91 | // @return none 92 | // ************************************************************************************************* 93 | void battery_measurement(void) 94 | { 95 | u16 voltage; 96 | 97 | // Convert external battery voltage (ADC12INCH_11=AVCC-AVSS/2) 98 | voltage = adc12_single_conversion(REFVSEL_1, ADC12SHT0_10, ADC12INCH_11); 99 | 100 | // Convert ADC value to "x.xx V" 101 | // Ideally we have A11=0->AVCC=0V ... A11=4095(2^12-1)->AVCC=4V 102 | // --> (A11/4095)*4V=AVCC --> AVCC=(A11*4)/4095 103 | voltage = (voltage * 2 * 2) / 41; 104 | 105 | // Correct measured voltage with calibration value 106 | voltage += sBatt.offset; 107 | 108 | // Discard values that are clearly outside the measurement range 109 | if (voltage > BATTERY_HIGH_THRESHOLD) 110 | { 111 | voltage = sBatt.voltage; 112 | } 113 | 114 | // Filter battery voltage 115 | sBatt.voltage = ((voltage * 2) + (sBatt.voltage * 8)) / 10; 116 | 117 | // If battery voltage falls below low battery threshold, set system flag and modify LINE2 118 | // display function pointer 119 | if (sBatt.voltage < BATTERY_LOW_THRESHOLD) 120 | { 121 | sys.flag.low_battery = 1; 122 | 123 | // Set sticky battery icon 124 | display_symbol(LCD_SYMB_BATTERY, SEG_ON); 125 | } 126 | else 127 | { 128 | sys.flag.low_battery = 0; 129 | 130 | // Clear sticky battery icon 131 | display_symbol(LCD_SYMB_BATTERY, SEG_OFF); 132 | } 133 | // Update LINE2 134 | display.flag.line2_full_update = 1; 135 | 136 | // Indicate to display function that new value is available 137 | display.flag.update_battery_voltage = 1; 138 | } 139 | 140 | // ************************************************************************************************* 141 | // @fn display_battery_V 142 | // @brief Display routine for battery voltage. 143 | // @param u8 line LINE2 144 | // u8 update DISPLAY_LINE_UPDATE_FULL, DISPLAY_LINE_CLEAR 145 | // @return none 146 | // ************************************************************************************************* 147 | void display_battery_V(u8 line, u8 update) 148 | { 149 | u8 *str; 150 | 151 | // Redraw line 152 | if (update == DISPLAY_LINE_UPDATE_FULL) 153 | { 154 | // Set battery and V icon 155 | display_symbol(LCD_SYMB_BATTERY, SEG_ON); 156 | 157 | // Menu item is visible 158 | sBatt.state = MENU_ITEM_VISIBLE; 159 | 160 | // Display result in xx.x format 161 | str = int_to_array(sBatt.voltage, 3, 0); 162 | 163 | display_chars(LCD_SEG_L2_2_0, str, SEG_ON); 164 | display_symbol(LCD_SEG_L2_DP, SEG_ON); 165 | } 166 | else if (update == DISPLAY_LINE_UPDATE_PARTIAL) 167 | { 168 | // Display result in xx.x format 169 | str = int_to_array(sBatt.voltage, 3, 0); 170 | 171 | display_chars(LCD_SEG_L2_2_0, str, SEG_ON); 172 | 173 | display.flag.update_battery_voltage = 0; 174 | } 175 | else if (update == DISPLAY_LINE_CLEAR) 176 | { 177 | // Menu item is not visible 178 | sBatt.state = MENU_ITEM_NOT_VISIBLE; 179 | 180 | // Clear function-specific symbols 181 | display_symbol(LCD_SYMB_BATTERY, SEG_OFF); 182 | } 183 | } 184 | 185 | -------------------------------------------------------------------------------- /driver/buzzer.c: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | // Buzzer functions. 36 | // ************************************************************************************************* 37 | 38 | // ************************************************************************************************* 39 | // Include section 40 | 41 | // system 42 | #include "project.h" 43 | 44 | // driver 45 | #include "buzzer.h" 46 | #include "timer.h" 47 | #include "display.h" 48 | 49 | // logic 50 | #include "alarm.h" 51 | 52 | // ************************************************************************************************* 53 | // Prototypes section 54 | void toggle_buzzer(void); 55 | void countdown_buzzer(void); 56 | 57 | // ************************************************************************************************* 58 | // Defines section 59 | 60 | // ************************************************************************************************* 61 | // Global Variable section 62 | struct buzzer sBuzzer; 63 | 64 | // ************************************************************************************************* 65 | // Extern section 66 | //extern u16 timer0_A3_ticks_g; 67 | 68 | // ************************************************************************************************* 69 | // @fn reset_buzzer 70 | // @brief Init buzzer variables 71 | // @param none 72 | // @return none 73 | // ************************************************************************************************* 74 | void reset_buzzer(void) 75 | { 76 | sBuzzer.time = 0; 77 | sBuzzer.state = BUZZER_OFF; 78 | } 79 | 80 | // ************************************************************************************************* 81 | // @fn start_buzzer 82 | // @brief Start buzzer output for a number of cylces 83 | // @param u8 cycles Keep buzzer output for number of cycles 84 | // u16 on_time Output buzzer for "on_time" ACLK ticks 85 | // u16 off_time Do not output buzzer for "off_time" ACLK ticks 86 | // @return none 87 | // ************************************************************************************************* 88 | void start_buzzer(u8 cycles, u16 on_time, u16 off_time) 89 | { 90 | // Store new buzzer duration while buzzer is off 91 | if (sBuzzer.time == 0) 92 | { 93 | sBuzzer.time = cycles; 94 | sBuzzer.on_time = on_time; 95 | sBuzzer.off_time = off_time; 96 | 97 | // Need to init every time, because SimpliciTI claims same timer 98 | // Reset TA1R, set up mode, TA1 runs from 32768Hz ACLK 99 | TA1CTL = TACLR | MC_1 | TASSEL__ACLK; 100 | 101 | // Set PWM frequency 102 | TA1CCR0 = BUZZER_TIMER_STEPS; 103 | 104 | // Enable IRQ, set output mode "toggle" 105 | TA1CCTL0 = OUTMOD_4; 106 | 107 | // Allow buzzer PWM output on P2.7 108 | P2SEL |= BIT7; 109 | 110 | // Activate Timer0_A3 periodic interrupts 111 | fptr_Timer0_A3_function = toggle_buzzer; 112 | Timer0_A3_Start(sBuzzer.on_time); 113 | 114 | // Preload timer advance variable 115 | sTimer.timer0_A3_ticks = sBuzzer.off_time; 116 | 117 | // Start with buzzer output on 118 | sBuzzer.state = BUZZER_ON_OUTPUT_ENABLED; 119 | } 120 | } 121 | 122 | // ************************************************************************************************* 123 | // @fn toggle_buzzer 124 | // @brief Keeps track of buzzer on/off duty cycle 125 | // @param none 126 | // @return none 127 | // ************************************************************************************************* 128 | void toggle_buzzer(void) 129 | { 130 | // Turn off buzzer 131 | if (sBuzzer.state == BUZZER_ON_OUTPUT_ENABLED) 132 | { 133 | // Stop PWM timer 134 | TA1CTL &= ~(BIT4 | BIT5); 135 | 136 | // Reset and disable buzzer PWM output 137 | P2OUT &= ~BIT7; 138 | P2SEL &= ~BIT7; 139 | 140 | // Update buzzer state 141 | sBuzzer.state = BUZZER_ON_OUTPUT_DISABLED; 142 | 143 | // Reload Timer0_A4 IRQ to restart output 144 | sTimer.timer0_A3_ticks = sBuzzer.on_time; 145 | } 146 | else // Turn on buzzer 147 | { 148 | // Decrement buzzer total cycles 149 | countdown_buzzer(); 150 | 151 | // Reload Timer0_A4 to stop output if sBuzzer.time > 0 152 | if (sBuzzer.state != BUZZER_OFF) 153 | { 154 | // Reset timer TA1 155 | TA1R = 0; 156 | TA1CTL |= MC_1; 157 | 158 | // Enable buzzer PWM output 159 | P2SEL |= BIT7; 160 | 161 | // Update buzzer state 162 | sBuzzer.state = BUZZER_ON_OUTPUT_ENABLED; 163 | 164 | // Reload Timer0_A4 IRQ to turn off output 165 | sTimer.timer0_A3_ticks = sBuzzer.off_time; 166 | } 167 | } 168 | } 169 | 170 | // ************************************************************************************************* 171 | // @fn stop_buzzer 172 | // @brief Stop buzzer output 173 | // @param none 174 | // @return none 175 | // ************************************************************************************************* 176 | void stop_buzzer(void) 177 | { 178 | // Stop PWM timer 179 | TA1CTL &= ~(BIT4 | BIT5); 180 | 181 | // Disable buzzer PWM output 182 | P2OUT &= ~BIT7; 183 | P2SEL &= ~BIT7; 184 | 185 | // Clear PWM timer interrupt 186 | TA1CCTL0 &= ~CCIE; 187 | 188 | // Disable periodic start/stop interrupts 189 | Timer0_A3_Stop(); 190 | 191 | // Clear variables 192 | reset_buzzer(); 193 | } 194 | 195 | // ************************************************************************************************* 196 | // @fn is_buzzer 197 | // @brief Check if buzzer is operating 198 | // @param none 199 | // @return u8 1 = Buzzer is operating, 0 = Buzzer is off 200 | // ************************************************************************************************* 201 | u8 is_buzzer(void) 202 | { 203 | return (sBuzzer.state != BUZZER_OFF); 204 | } 205 | 206 | // ************************************************************************************************* 207 | // @fn countdown_buzzer 208 | // @brief Decrement active buzzer time. Turn off buzzer if cycle end reached. 209 | // @param none 210 | // @return none 211 | // ************************************************************************************************* 212 | void countdown_buzzer(void) 213 | { 214 | // Stop buzzer when reaching 0 cycles 215 | if (--sBuzzer.time == 0) 216 | { 217 | stop_buzzer(); 218 | } 219 | } 220 | 221 | -------------------------------------------------------------------------------- /driver/cma_as.c: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | // VTI CMA3000-D0x acceleration sensor driver functions 36 | // ************************************************************************************************* 37 | 38 | // ************************************************************************************************* 39 | // Include section 40 | 41 | // system 42 | #include "project.h" 43 | 44 | // logic 45 | #include "simpliciti.h" 46 | 47 | // driver 48 | #include "cma_as.h" 49 | #include "as.h" 50 | #include "timer.h" 51 | #include "display.h" 52 | 53 | // ************************************************************************************************* 54 | // Prototypes section 55 | 56 | // ************************************************************************************************* 57 | // Defines section 58 | 59 | // ================================================================================================= 60 | // CMA3000-D0x acceleration sensor configuration 61 | // ================================================================================================= 62 | // DCO frequency division factor determining speed of the acceleration sensor SPI interface 63 | // Speed in Hz = 12MHz / AS_BR_DIVIDER (max. 500kHz) 64 | #define CMA_AS_BR_DIVIDER (30u) 65 | 66 | // Acceleration measurement range in g 67 | // Valid ranges are: 2 and 8 68 | #define CMA_AS_RANGE (2u) 69 | 70 | // Sample rate for acceleration values in Hz 71 | // Valid sample rates for 2g range are: 100, 400 72 | // Valid sample rates for 8g range are: 40, 100, 400 73 | #define CMA_AS_SAMPLE_RATE (100u) 74 | 75 | // ************************************************************************************************* 76 | // Global Variable section 77 | 78 | // ************************************************************************************************* 79 | // Extern section 80 | 81 | 82 | // ************************************************************************************************* 83 | // @fn cma_as_start 84 | // @brief Power-up and initialize acceleration sensor 85 | // @param none 86 | // @return none 87 | // ************************************************************************************************* 88 | void cma_as_start(void) 89 | { 90 | volatile u16 Counter_u16; 91 | u8 bConfig; 92 | 93 | // Initialize SPI interface to acceleration sensor 94 | AS_SPI_CTL0 |= UCSYNC | UCMST | UCMSB // SPI master, 8 data bits, MSB first, 95 | | UCCKPH; // clock idle low, data output on falling 96 | // edge 97 | AS_SPI_CTL1 |= UCSSEL1; // SMCLK as clock source 98 | AS_SPI_BR0 = CMA_AS_BR_DIVIDER; // Low byte of division factor for baud rate 99 | AS_SPI_BR1 = 0x00; // High byte of division factor for baud 100 | // rate 101 | AS_SPI_CTL1 &= ~UCSWRST; // Start SPI hardware 102 | 103 | // Configure interface pins 104 | as_start(); 105 | 106 | // Configure sensor and start to sample data 107 | #if (CMA_AS_RANGE == 2) 108 | bConfig = 0x80; 109 | # if (CMA_AS_SAMPLE_RATE == 100) 110 | bConfig |= 0x02; 111 | # elif (CMA_AS_SAMPLE_RATE == 400) 112 | bConfig |= 0x04; 113 | # else 114 | # error "Sample rate not supported" 115 | # endif 116 | #elif (CMA_AS_RANGE == 8) 117 | bConfig = 0x00; 118 | # if (CMA_AS_SAMPLE_RATE == 40) 119 | bConfig |= 0x06; 120 | # elif (CMA_AS_SAMPLE_RATE == 100) 121 | bConfig |= 0x02; 122 | # elif (CMA_AS_SAMPLE_RATE == 400) 123 | bConfig |= 0x04; 124 | # else 125 | # error "Sample rate not supported" 126 | # endif 127 | #else 128 | # error "Measurement range not supported" 129 | #endif 130 | 131 | // Reset sensor 132 | cma_as_write_register(0x04, 0x02); 133 | cma_as_write_register(0x04, 0x0A); 134 | cma_as_write_register(0x04, 0x04); 135 | 136 | // Wait 5 ms before starting sensor output 137 | Timer0_A4_Delay(CONV_MS_TO_TICKS(5)); 138 | 139 | // Set 2g measurement range, start to output data with 100Hz rate 140 | cma_as_write_register(0x02, bConfig); 141 | } 142 | 143 | // ************************************************************************************************* 144 | // @fn cma_as_stop 145 | // @brief Power down acceleration sensor 146 | // @param none 147 | // @return none 148 | // ************************************************************************************************* 149 | void cma_as_stop(void) 150 | { 151 | as_stop(); 152 | } 153 | 154 | // ************************************************************************************************* 155 | // @fn cma_as_read_register 156 | // @brief Read a byte from the acceleration sensor 157 | // @param u8 bAddress Register address 158 | // @return u8 0 or bResult Register content 159 | // If the returned value is 0 there was an error. 160 | // ************************************************************************************************* 161 | u8 cma_as_read_register(u8 bAddress) 162 | { 163 | bAddress <<= 2; // Address to be shifted left by 2 and 164 | // RW bit to be reset 165 | 166 | return as_read_register(bAddress); 167 | } 168 | 169 | // ************************************************************************************************* 170 | // @fn cma_as_write_register 171 | // @brief Write a byte to the acceleration sensor 172 | // @param u8 bAddress Register address 173 | // u8 bData Data to write 174 | // @return u8 0 or bResult Register content 175 | // If the returned value is 0 there was an error. 176 | // ************************************************************************************************* 177 | u8 cma_as_write_register(u8 bAddress, u8 bData) 178 | { 179 | bAddress <<= 2; // Address to be shifted left by 1 180 | bAddress |= BIT1; // RW bit to be set 181 | 182 | return as_write_register(bAddress, bData); 183 | } 184 | 185 | // ************************************************************************************************* 186 | // @fn cma_as_get_data 187 | // @brief Service routine to read acceleration values. 188 | // @param none 189 | // @return none 190 | // ************************************************************************************************* 191 | void cma_as_get_data(u8 * data) 192 | { 193 | // Exit if sensor is not powered up 194 | if ((AS_PWR_OUT & AS_PWR_PIN) != AS_PWR_PIN) 195 | return; 196 | 197 | // Store X/Y/Z acceleration data in buffer 198 | *(data + 0) = cma_as_read_register(0x06); 199 | *(data + 1) = cma_as_read_register(0x07); 200 | *(data + 2) = cma_as_read_register(0x08); 201 | } 202 | 203 | -------------------------------------------------------------------------------- /logic/menu.c: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | // Menu management functions. 36 | // ************************************************************************************************* 37 | 38 | // ************************************************************************************************* 39 | // Include section 40 | 41 | // system 42 | #include "project.h" 43 | 44 | // driver 45 | #include "display.h" 46 | 47 | // logic 48 | #include "menu.h" 49 | #include "user.h" 50 | #include "clock.h" 51 | #include "date.h" 52 | #include "alarm.h" 53 | #include "stopwatch.h" 54 | #include "temperature.h" 55 | #include "altitude.h" 56 | #include "battery.h" 57 | //#include "bluerobin.h" 58 | #include "rfsimpliciti.h" 59 | #include "acceleration.h" 60 | #include "rfbsl.h" 61 | #include "baro.h" 62 | 63 | // ************************************************************************************************* 64 | // Defines section 65 | #define FUNCTION(function) function 66 | 67 | // ************************************************************************************************* 68 | // Global Variable section 69 | const struct menu *ptrMenu_L1 = NULL; 70 | const struct menu *ptrMenu_L2 = NULL; 71 | 72 | // ************************************************************************************************* 73 | // Global Variable section 74 | 75 | void display_nothing(u8 line, u8 update) 76 | { 77 | } 78 | 79 | u8 update_time(void) 80 | { 81 | return (display.flag.update_time); 82 | } 83 | 84 | u8 update_stopwatch(void) 85 | { 86 | return (display.flag.update_stopwatch); 87 | } 88 | 89 | u8 update_date(void) 90 | { 91 | return (display.flag.update_date); 92 | } 93 | 94 | u8 update_alarm(void) 95 | { 96 | return (display.flag.update_alarm); 97 | } 98 | 99 | u8 update_temperature(void) 100 | { 101 | return (display.flag.update_temperature); 102 | } 103 | 104 | u8 update_battery_voltage(void) 105 | { 106 | return (display.flag.update_battery_voltage); 107 | } 108 | 109 | u8 update_acceleration(void) 110 | { 111 | return (display.flag.update_acceleration); 112 | } 113 | 114 | // ************************************************************************************************* 115 | // User navigation ( [____] = default menu item after reset ) 116 | // 117 | // LINE1: [Time] -> Alarm -> Temperature -> Altitude -> Heart rate -> Speed -> Acceleration 118 | // 119 | // LINE2: [Date] -> Stopwatch -> Battery -> ACC -> PPT -> SYNC -> Calories/Distance --> RFBSL 120 | // ************************************************************************************************* 121 | 122 | // Line1 - Time 123 | const struct menu menu_L1_Time = { 124 | FUNCTION(sx_time), // direct function 125 | FUNCTION(mx_time), // sub menu function 126 | FUNCTION(display_time), // display function 127 | FUNCTION(update_time), // new display data 128 | &menu_L1_Temperature, 129 | }; 130 | 131 | // Line1 - Temperature 132 | const struct menu menu_L1_Temperature = { 133 | FUNCTION(dummy), // direct function 134 | FUNCTION(mx_temperature), // sub menu function 135 | FUNCTION(display_temperature), // display function 136 | FUNCTION(update_temperature), // new display data 137 | &menu_L1_Altitude, 138 | }; 139 | 140 | // Line1 - Altitude 141 | const struct menu menu_L1_Altitude = { 142 | FUNCTION(sx_altitude), // direct function 143 | FUNCTION(mx_altitude), // sub menu function 144 | FUNCTION(display_altitude), // display function 145 | FUNCTION(update_time), // new display data 146 | &menu_L1_Baro, 147 | }; 148 | 149 | // Line1 - Barometer 150 | const struct menu menu_L1_Baro = { 151 | FUNCTION(dummy), // direct function 152 | FUNCTION(dummy), // sub menu function 153 | FUNCTION(display_barometer), // display function 154 | FUNCTION(update_time), // new display data 155 | &menu_L1_Alarm, 156 | }; 157 | 158 | // Line1 - Alarm 159 | const struct menu menu_L1_Alarm = { 160 | FUNCTION(sx_alarm), // direct function 161 | FUNCTION(mx_alarm), // sub menu function 162 | FUNCTION(display_alarm), // display function 163 | FUNCTION(update_alarm), // new display data 164 | &menu_L1_Acceleration, 165 | }; 166 | 167 | 168 | // Line1 - Acceleration 169 | const struct menu menu_L1_Acceleration = { 170 | FUNCTION(sx_acceleration), // direct function 171 | FUNCTION(dummy), // sub menu function 172 | FUNCTION(display_acceleration), // display function 173 | FUNCTION(update_acceleration), // new display data 174 | &menu_L1_Time, 175 | }; 176 | 177 | 178 | // Line2 - Date 179 | const struct menu menu_L2_Date = { 180 | FUNCTION(sx_date), // direct function 181 | FUNCTION(mx_date), // sub menu function 182 | FUNCTION(display_date), // display function 183 | FUNCTION(update_date), // new display data 184 | &menu_L2_Battery, 185 | }; 186 | 187 | // Line2 - Battery 188 | const struct menu menu_L2_Battery = { 189 | FUNCTION(dummy), // direct function 190 | FUNCTION(dummy), // sub menu function 191 | FUNCTION(display_battery_V), // display function 192 | FUNCTION(update_battery_voltage), // new display data 193 | &menu_L2_Sync, 194 | }; 195 | 196 | // Line2 - SXNC (synchronization/data download via SimpliciTI) 197 | const struct menu menu_L2_Sync = { 198 | FUNCTION(sx_sync), // direct function 199 | FUNCTION(dummy), // sub menu function 200 | FUNCTION(display_sync), // display function 201 | FUNCTION(update_time), // new display data 202 | &menu_L2_Ctrl, 203 | }; 204 | 205 | 206 | // Line2 - PPT (button events via SimpliciTI) 207 | const struct menu menu_L2_Ctrl = { 208 | FUNCTION(sx_ctrl), // direct function 209 | FUNCTION(dummy), // sub menu function 210 | FUNCTION(display_ctrl), // display function 211 | FUNCTION(update_time), // new display data 212 | &menu_L2_RFAccel, 213 | }; 214 | 215 | // Line2 - ACC (acceleration data + button events via SimpliciTI) 216 | const struct menu menu_L2_RFAccel = { 217 | FUNCTION(sx_rf), // direct function 218 | FUNCTION(dummy), // sub menu function 219 | FUNCTION(display_rf), // display function 220 | FUNCTION(update_time), // new display data 221 | &menu_L2_Stopwatch, 222 | }; 223 | 224 | // Line2 - Stopwatch 225 | const struct menu menu_L2_Stopwatch = { 226 | FUNCTION(sx_stopwatch), // direct function 227 | FUNCTION(mx_stopwatch), // sub menu function 228 | FUNCTION(display_stopwatch), // display function 229 | FUNCTION(update_stopwatch), // new display data 230 | &menu_L2_RFBSL, 231 | }; 232 | 233 | // Line2 - RFBSL 234 | const struct menu menu_L2_RFBSL = { 235 | FUNCTION(sx_rfbsl), // direct function 236 | FUNCTION(dummy), // sub menu function 237 | FUNCTION(display_rfbsl), // display function 238 | FUNCTION(update_time), // new display data 239 | &menu_L2_Date, 240 | }; 241 | -------------------------------------------------------------------------------- /driver/rf1a.c: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Actual revision: $Revision: $ 4 | // Revision label: $Name: $ 5 | // Revision state: $State: $ 6 | // 7 | // ************************************************************************************************* 8 | // Radio core access functions. Taken from TI reference code for CC430. 9 | // ************************************************************************************************* 10 | 11 | // ************************************************************************************************* 12 | // Include section 13 | 14 | // system 15 | #include 16 | 17 | // driver 18 | #include "rf1a.h" 19 | 20 | // ************************************************************************************************* 21 | // Global section 22 | 23 | // ************************************************************************************************* 24 | // Define section 25 | #define st(x) do { x } while (__LINE__ == -1) 26 | #define ENTER_CRITICAL_SECTION(x) st(x = __get_interrupt_state(); __disable_interrupt(); ) 27 | #define EXIT_CRITICAL_SECTION(x) __set_interrupt_state(x) 28 | 29 | // ************************************************************************************************* 30 | // @fn Strobe 31 | // @brief Send command to radio. 32 | // @param unsigned char strobe Command to radio 33 | // @return statusByte Radio core status 34 | // ************************************************************************************************* 35 | unsigned char Strobe(unsigned char strobe) 36 | { 37 | u8 statusByte = 0; 38 | u16 int_state, gdo_state; 39 | 40 | // Check for valid strobe command 41 | if ((strobe == 0xBD) || ((strobe > RF_SRES) && (strobe < RF_SNOP))) 42 | { 43 | ENTER_CRITICAL_SECTION(int_state); 44 | 45 | // Clear the Status read flag 46 | RF1AIFCTL1 &= ~(RFSTATIFG); 47 | 48 | // Wait for radio to be ready for next instruction 49 | while (!(RF1AIFCTL1 & RFINSTRIFG)) ; 50 | 51 | // Write the strobe instruction 52 | if ((strobe > RF_SRES) && (strobe < RF_SNOP)) 53 | { 54 | 55 | gdo_state = ReadSingleReg(IOCFG2); // buffer IOCFG2 state 56 | WriteSingleReg(IOCFG2, 0x29); // c-ready to GDO2 57 | 58 | RF1AINSTRB = strobe; 59 | if ((RF1AIN & 0x04) == 0x04) // chip at sleep mode 60 | { 61 | if ((strobe == RF_SXOFF) || (strobe == RF_SPWD) || (strobe == RF_SWOR)) 62 | { 63 | } 64 | else 65 | { 66 | while ((RF1AIN & 0x04) == 0x04) ; // c-ready ? 67 | __delay_cycles(9800); // Delay for ~810usec at 12MHz CPU clock 68 | } 69 | } 70 | WriteSingleReg(IOCFG2, gdo_state); // restore IOCFG2 setting 71 | } 72 | else // chip active mode 73 | { 74 | RF1AINSTRB = strobe; 75 | } 76 | statusByte = RF1ASTATB; 77 | while (!(RF1AIFCTL1 & RFSTATIFG)) ; 78 | EXIT_CRITICAL_SECTION(int_state); 79 | } 80 | return statusByte; 81 | } 82 | 83 | // ************************************************************************************************* 84 | // @fn ResetRadioCore 85 | // @brief Software reset radio core. 86 | // @param none 87 | // @return none 88 | // ************************************************************************************************* 89 | void ResetRadioCore(void) 90 | { 91 | Strobe(RF_SRES); // Reset the Radio Core 92 | Strobe(RF_SNOP); // Reset Radio Pointer 93 | } 94 | 95 | // ************************************************************************************************* 96 | // @fn ReadSingleReg 97 | // @brief Read byte from register. 98 | // @param none 99 | // @return none 100 | // ************************************************************************************************* 101 | unsigned char ReadSingleReg(unsigned char addr) 102 | { 103 | unsigned char x; 104 | u16 int_state; 105 | 106 | ENTER_CRITICAL_SECTION(int_state); 107 | 108 | RF1AINSTR1B = (addr | RF_REGRD); 109 | x = RF1ADOUT1B; 110 | 111 | EXIT_CRITICAL_SECTION(int_state); 112 | 113 | return x; 114 | } 115 | 116 | // ************************************************************************************************* 117 | // @fn WriteSingleReg 118 | // @brief Write byte to register. 119 | // @param none 120 | // @return none 121 | // ************************************************************************************************* 122 | void WriteSingleReg(unsigned char addr, unsigned char value) 123 | { 124 | volatile unsigned int i; 125 | u16 int_state; 126 | 127 | ENTER_CRITICAL_SECTION(int_state); 128 | 129 | while (!(RF1AIFCTL1 & RFINSTRIFG)) ; // Wait for the Radio to be ready for the next 130 | // instruction 131 | 132 | RF1AINSTRW = ((addr | RF_REGWR) << 8) + value; // Send address + Instruction 133 | while (!(RFDINIFG & RF1AIFCTL1)) ; 134 | 135 | i = RF1ADOUTB; // Reset RFDOUTIFG flag which contains status 136 | // byte 137 | 138 | EXIT_CRITICAL_SECTION(int_state); 139 | } 140 | 141 | // ************************************************************************************************* 142 | // @fn ReadBurstReg 143 | // @brief Read sequence of bytes from register. 144 | // @param none 145 | // @return none 146 | // ************************************************************************************************* 147 | void ReadBurstReg(unsigned char addr, unsigned char *buffer, unsigned char count) 148 | { 149 | unsigned int i; 150 | u16 int_state; 151 | 152 | ENTER_CRITICAL_SECTION(int_state); 153 | 154 | while (!(RF1AIFCTL1 & RFINSTRIFG)) ; // Wait for the Radio to be ready for next instruction 155 | RF1AINSTR1B = (addr | RF_REGRD); // Send address + Instruction 156 | 157 | for (i = 0; i < (count - 1); i++) 158 | { 159 | while (!(RFDOUTIFG & RF1AIFCTL1)) ; // Wait for the Radio Core to update the RF1ADOUTB reg 160 | buffer[i] = RF1ADOUT1B; // Read DOUT from Radio Core + clears RFDOUTIFG 161 | // Also initiates auo-read for next DOUT byte 162 | } 163 | buffer[count - 1] = RF1ADOUT0B; // Store the last DOUT from Radio Core 164 | 165 | EXIT_CRITICAL_SECTION(int_state); 166 | } 167 | 168 | // ************************************************************************************************* 169 | // @fn WriteBurstReg 170 | // @brief Write sequence of bytes to register. 171 | // @param none 172 | // @return none 173 | // ************************************************************************************************* 174 | void WriteBurstReg(unsigned char addr, unsigned char *buffer, unsigned char count) 175 | { 176 | // Write Burst works wordwise not bytewise - bug known already 177 | unsigned char i; 178 | u16 int_state; 179 | 180 | ENTER_CRITICAL_SECTION(int_state); 181 | 182 | while (!(RF1AIFCTL1 & RFINSTRIFG)) ; // Wait for the Radio to be ready for next 183 | // instruction 184 | RF1AINSTRW = ((addr | RF_REGWR) << 8) + buffer[0]; // Send address + Instruction 185 | 186 | for (i = 1; i < count; i++) 187 | { 188 | RF1ADINB = buffer[i]; // Send data 189 | while (!(RFDINIFG & RF1AIFCTL1)) ; // Wait for TX to finish 190 | } 191 | i = RF1ADOUTB; // Reset RFDOUTIFG flag which contains status 192 | // byte 193 | 194 | EXIT_CRITICAL_SECTION(int_state); 195 | } 196 | 197 | // ************************************************************************************************* 198 | // @fn WritePATable 199 | // @brief Write data to power table 200 | // @param unsigned char value Value to write 201 | // @return none 202 | // ************************************************************************************************* 203 | void WritePATable(unsigned char value) 204 | { 205 | unsigned char readbackPATableValue = 0; 206 | u16 int_state; 207 | 208 | ENTER_CRITICAL_SECTION(int_state); 209 | 210 | while (readbackPATableValue != value) 211 | { 212 | while (!(RF1AIFCTL1 & RFINSTRIFG)) ; 213 | RF1AINSTRW = 0x7E00 + value; // PA Table write (burst) 214 | 215 | while (!(RF1AIFCTL1 & RFINSTRIFG)) ; 216 | RF1AINSTRB = RF_SNOP; // reset pointer 217 | 218 | while (!(RF1AIFCTL1 & RFINSTRIFG)) ; 219 | RF1AINSTRB = 0xFE; // PA Table read (burst) 220 | 221 | while (!(RF1AIFCTL1 & RFDINIFG)) ; 222 | RF1ADINB = 0x00; //dummy write 223 | 224 | while (!(RF1AIFCTL1 & RFDOUTIFG)) ; 225 | readbackPATableValue = RF1ADOUT0B; 226 | 227 | while (!(RF1AIFCTL1 & RFINSTRIFG)) ; 228 | RF1AINSTRB = RF_SNOP; 229 | } 230 | 231 | EXIT_CRITICAL_SECTION(int_state); 232 | } 233 | 234 | -------------------------------------------------------------------------------- /driver/bmp_as.c: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | // Bosch BMA250 acceleration sensor driver functions 36 | // ************************************************************************************************* 37 | 38 | 39 | // ************************************************************************************************* 40 | // Include section 41 | 42 | // system 43 | #include "project.h" 44 | 45 | // logic 46 | #include "simpliciti.h" 47 | 48 | // driver 49 | #include "bmp_as.h" 50 | #include "as.h" 51 | #include "timer.h" 52 | #include "display.h" 53 | 54 | 55 | // ************************************************************************************************* 56 | // Prototypes section 57 | 58 | // ************************************************************************************************* 59 | // Defines section 60 | 61 | // ================================================================================================= 62 | // BMA250 acceleration sensor configuration 63 | // ================================================================================================= 64 | // DCO frequency division factor determining speed of the acceleration sensor SPI interface 65 | // Speed in Hz = 12MHz / AS_BR_DIVIDER (max. 10MHz) 66 | #define BMP_AS_BR_DIVIDER (2u) 67 | 68 | // Acceleration measurement range in g 69 | // Valid ranges are: 2, 4, 8, 16 70 | #define BMP_AS_RANGE (2u) 71 | 72 | // Use in-sensor filtering 73 | // unfiltered data is always sampled at 2kHz 74 | #define BMP_AS_FILTERING 75 | 76 | // Bandwidth for filtered acceleration data in Hz (Sampling rate is twice the bandwidth) 77 | // Valid bandwidths are: 8, 16, 31, 63, 125, 250, 500, 1000 78 | #define BMP_AS_BANDWIDTH (63u) 79 | 80 | // Sleep phase duration in ms 81 | // Valid sleep phase durations are: 1, 2, 4, 6, 10, 25, 50 82 | #define BMP_AS_SLEEPPHASE (6u) 83 | 84 | 85 | // ************************************************************************************************* 86 | // Global Variable section 87 | 88 | // ************************************************************************************************* 89 | // Extern section 90 | 91 | 92 | // ************************************************************************************************* 93 | // @fn bmp_as_start 94 | // @brief Power-up and initialize acceleration sensor 95 | // @param none 96 | // @return none 97 | // ************************************************************************************************* 98 | void bmp_as_start(void) 99 | { 100 | u8 bGRange; // g Range; 101 | u8 bBwd; // Bandwidth 102 | u8 bSleep; // Sleep phase 103 | 104 | // Initialize SPI interface to acceleration sensor 105 | AS_SPI_CTL0 |= UCSYNC | UCMST | UCMSB // SPI master, 8 data bits, MSB first, 106 | | UCCKPH; // clock idle low, data output on falling edge 107 | AS_SPI_CTL1 |= UCSSEL1; // SMCLK as clock source 108 | AS_SPI_BR0 = BMP_AS_BR_DIVIDER; // Low byte of division factor for baud rate 109 | AS_SPI_BR1 = 0x00; // High byte of division factor for baud rate 110 | AS_SPI_CTL1 &= ~UCSWRST; // Start SPI hardware 111 | 112 | // Configure interface pins 113 | as_start(); 114 | 115 | // Configure sensor and start to sample data 116 | #if (BMP_AS_RANGE == 2) 117 | bGRange = 0x03; 118 | #elif (BMP_AS_RANGE == 4) 119 | bGRange = 0x05; 120 | #elif (BMP_AS_RANGE == 8) 121 | bGRange = 0x08; 122 | #elif (BMP_AS_RANGE == 16) 123 | bGRange = 0x0C; 124 | #else 125 | #error "Measurement range not supported" 126 | #endif 127 | 128 | #if (BMP_AS_BANDWIDTH == 8) 129 | bBwd = 0x08; 130 | #elif (BMP_AS_BANDWIDTH == 16) 131 | bBwd = 0x09; 132 | #elif (BMP_AS_BANDWIDTH == 31) 133 | bBwd = 0x0A; 134 | #elif (BMP_AS_BANDWIDTH == 63) 135 | bBwd = 0x0B; 136 | #elif (BMP_AS_BANDWIDTH == 125) 137 | bBwd = 0x0C; 138 | #elif (BMP_AS_BANDWIDTH == 250) 139 | bBwd = 0x0D; 140 | #elif (BMP_AS_BANDWIDTH == 500) 141 | bBwd = 0x0E; 142 | #elif (BMP_AS_BANDWIDTH == 1000) 143 | bBwd = 0x0F; 144 | #else 145 | #error "Sample rate not supported" 146 | #endif 147 | 148 | #if (BMP_AS_SLEEPPHASE == 1) 149 | bSleep = 0x4C; 150 | #elif (BMP_AS_SLEEPPHASE == 2) 151 | bSleep = 0x4E; 152 | #elif (BMP_AS_SLEEPPHASE == 4) 153 | bSleep = 0x50; 154 | #elif (BMP_AS_SLEEPPHASE == 6) 155 | bSleep = 0x52; 156 | #elif (BMP_AS_SLEEPPHASE == 10) 157 | bSleep = 0x54; 158 | #elif (BMP_AS_SLEEPPHASE == 25) 159 | bSleep = 0x56; 160 | #elif (BMP_AS_SLEEPPHASE == 50) 161 | bSleep = 0x58; 162 | #else 163 | #error "Sleep phase duration not supported" 164 | #endif 165 | 166 | // write sensor configuration 167 | bmp_as_write_register(BMP_GRANGE, bGRange); // Set measurement range 168 | bmp_as_write_register(BMP_BWD, bBwd); // Set filter bandwidth 169 | bmp_as_write_register(BMP_PM, bSleep); // Set filter bandwidth 170 | 171 | 172 | #ifndef BMP_AS_FILTERING 173 | bmp_as_write_register(BMP_SCR, 0x80); // acquire unfiltered acceleration data 174 | #endif 175 | // configure sensor interrupt 176 | bmp_as_write_register(BMP_IMR2, 0x01); // map new data interrupt to INT1 pin 177 | bmp_as_write_register(BMP_ISR2, 0x10); // enable new data interrupt 178 | 179 | // enable CC430 interrupt pin for data read out from acceleration sensor 180 | AS_INT_IFG &= ~AS_INT_PIN; // Reset flag 181 | AS_INT_IE |= AS_INT_PIN; // Enable interrupt 182 | } 183 | 184 | 185 | 186 | // ************************************************************************************************* 187 | // @fn bmp_as_stop 188 | // @brief Power down acceleration sensor 189 | // @param none 190 | // @return none 191 | // ************************************************************************************************* 192 | void bmp_as_stop(void) 193 | { 194 | as_stop(); 195 | } 196 | 197 | 198 | // ************************************************************************************************* 199 | // @fn bmp_as_read_register 200 | // @brief Read a byte from the acceleration sensor 201 | // @param u8 bAddress Register address 202 | // @return u8 Register content 203 | // ************************************************************************************************* 204 | u8 bmp_as_read_register(u8 bAddress) 205 | { 206 | bAddress |= BIT7; // set R/W bit for reading 207 | 208 | return as_read_register(bAddress); 209 | } 210 | 211 | // ************************************************************************************************* 212 | // @fn bmp_as_write_register 213 | // @brief Write a byte to the acceleration sensor 214 | // @param u8 bAddress Register address 215 | // u8 bData Data to write 216 | // @return u8 217 | // ************************************************************************************************* 218 | u8 bmp_as_write_register(u8 bAddress, u8 bData) 219 | { 220 | bAddress &= ~BIT8; // R/W bit to be not set 221 | 222 | return as_write_register(bAddress, bData); 223 | } 224 | 225 | 226 | // ************************************************************************************************* 227 | // @fn bmp_as_get_data 228 | // @brief Service routine to read acceleration values. 229 | // @param none 230 | // @return none 231 | // ************************************************************************************************* 232 | void bmp_as_get_data(u8 * data) 233 | { 234 | // Exit if sensor is not powered up 235 | if ((AS_PWR_OUT & AS_PWR_PIN) != AS_PWR_PIN) return; 236 | 237 | // Dummy read LSB from LSB acceleration data to update MSB (BMA250 datasheet 4.4.1) 238 | *(data+1) = bmp_as_read_register(BMP_ACC_X_LSB); 239 | *(data+0) = bmp_as_read_register(BMP_ACC_Y_LSB); 240 | *(data+2) = bmp_as_read_register(BMP_ACC_Z_LSB); 241 | // Store X/Y/Z MSB acceleration data in buffer 242 | *(data+1) = bmp_as_read_register(BMP_ACC_X_MSB); 243 | *(data+0) = bmp_as_read_register(BMP_ACC_Y_MSB); 244 | *(data+2) = bmp_as_read_register(BMP_ACC_Z_MSB); 245 | } 246 | 247 | 248 | -------------------------------------------------------------------------------- /logic/alarm.c: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | // Alarm routines. 36 | // ************************************************************************************************* 37 | 38 | // ************************************************************************************************* 39 | // Include section 40 | 41 | // system 42 | #include "project.h" 43 | 44 | // driver 45 | #include "display.h" 46 | #include "buzzer.h" 47 | #include "ports.h" 48 | 49 | // logic 50 | #include "alarm.h" 51 | #include "clock.h" 52 | #include "user.h" 53 | 54 | // ************************************************************************************************* 55 | // Prototypes section 56 | 57 | // ************************************************************************************************* 58 | // Defines section 59 | 60 | // ************************************************************************************************* 61 | // Global Variable section 62 | struct alarm sAlarm; 63 | 64 | // ************************************************************************************************* 65 | // Extern section 66 | 67 | // ************************************************************************************************* 68 | // @fn reset_alarm 69 | // @brief Resets alarmData to 09:30 70 | // @param none 71 | // @return none 72 | // ************************************************************************************************* 73 | void reset_alarm(void) 74 | { 75 | // Default alarm time 09:30 76 | sAlarm.hour = 9; 77 | sAlarm.minute = 30; 78 | 79 | // Alarm is initially off 80 | sAlarm.duration = ALARM_ON_DURATION; 81 | sAlarm.state = ALARM_DISABLED; 82 | } 83 | 84 | // ************************************************************************************************* 85 | // @fn check_alarm 86 | // @brief Check if current time matches alarm time 87 | // @param none 88 | // @return none 89 | // ************************************************************************************************* 90 | void check_alarm(void) 91 | { 92 | // Return if alarm is not enabled 93 | if (sAlarm.state != ALARM_ENABLED) 94 | return; 95 | 96 | // Compare current time and alarm time 97 | // Start with minutes - only 1/60 probability to match 98 | if (sTime.minute == sAlarm.minute) 99 | { 100 | if (sTime.hour == sAlarm.hour) 101 | { 102 | // Indicate that alarm is on 103 | sAlarm.state = ALARM_ON; 104 | } 105 | } 106 | } 107 | 108 | // ************************************************************************************************* 109 | // @fn stop_alarm 110 | // @brief Stop active alarm 111 | // @param none 112 | // @return none 113 | // ************************************************************************************************* 114 | void stop_alarm(void) 115 | { 116 | // Indicate that alarm is enabled, but not active 117 | sAlarm.state = ALARM_ENABLED; 118 | 119 | // Stop buzzer 120 | stop_buzzer(); 121 | } 122 | 123 | // ************************************************************************************************* 124 | // @fn sx_alarm 125 | // @brief Sx button turns alarm on/off. 126 | // @param u8 line LINE1 127 | // @return none 128 | // ************************************************************************************************* 129 | void sx_alarm(u8 line) 130 | { 131 | // UP: Alarm on, off 132 | if (button.flag.up) 133 | { 134 | // Toggle alarm state 135 | if (sAlarm.state == ALARM_DISABLED) 136 | { 137 | sAlarm.state = ALARM_ENABLED; 138 | 139 | // Show " on" message 140 | message.flag.prepare = 1; 141 | message.flag.type_alarm_on = 1; 142 | } 143 | else if (sAlarm.state == ALARM_ENABLED) 144 | { 145 | sAlarm.state = ALARM_DISABLED; 146 | 147 | // Show " off" message 148 | message.flag.prepare = 1; 149 | message.flag.type_alarm_off = 1; 150 | } 151 | } 152 | } 153 | 154 | // ************************************************************************************************* 155 | // @fn mx_alarm 156 | // @brief Set alarm time. 157 | // @param u8 line LINE1 158 | // @return none 159 | // ************************************************************************************************* 160 | void mx_alarm(u8 line) 161 | { 162 | u8 select; 163 | s32 hours; 164 | s32 minutes; 165 | u8 *str; 166 | 167 | // Clear display 168 | clear_display_all(); 169 | 170 | // Keep global values in case new values are discarded 171 | hours = sAlarm.hour; 172 | minutes = sAlarm.minute; 173 | 174 | // Display HH:MM (LINE1) 175 | str = int_to_array(hours, 2, 0); 176 | display_chars(LCD_SEG_L1_3_2, str, SEG_ON); 177 | display_symbol(LCD_SEG_L1_COL, SEG_ON); 178 | 179 | str = int_to_array(minutes, 2, 0); 180 | display_chars(LCD_SEG_L1_1_0, str, SEG_ON); 181 | 182 | // Init value index 183 | select = 0; 184 | 185 | // Loop values until all are set or user breaks set 186 | while (1) 187 | { 188 | // Idle timeout: exit without saving 189 | if (sys.flag.idle_timeout) 190 | break; 191 | 192 | // STAR (short): save, then exit 193 | if (button.flag.star) 194 | { 195 | // Store local variables in global alarm time 196 | sAlarm.hour = hours; 197 | sAlarm.minute = minutes; 198 | // Set display update flag 199 | display.flag.line1_full_update = 1; 200 | break; 201 | } 202 | 203 | switch (select) 204 | { 205 | case 0: // Set hour 206 | set_value(&hours, 2, 0, 0, 23, SETVALUE_ROLLOVER_VALUE + SETVALUE_DISPLAY_VALUE + 207 | SETVALUE_NEXT_VALUE, LCD_SEG_L1_3_2, 208 | display_hours); 209 | select = 1; 210 | break; 211 | 212 | case 1: // Set minutes 213 | set_value(&minutes, 2, 0, 0, 59, SETVALUE_ROLLOVER_VALUE + SETVALUE_DISPLAY_VALUE + 214 | SETVALUE_NEXT_VALUE, LCD_SEG_L1_1_0, 215 | display_value); 216 | select = 0; 217 | break; 218 | } 219 | } 220 | 221 | // Clear button flag 222 | button.all_flags = 0; 223 | 224 | // Indicate to display function that new value is available 225 | display.flag.update_alarm = 1; 226 | } 227 | 228 | // ************************************************************************************************* 229 | // @fn display_alarm 230 | // @brief Display alarm time. 24H / 12H time format. 231 | // @param u8 line LINE1, LINE2 232 | // u8 update DISPLAY_LINE_UPDATE_FULL, DISPLAY_LINE_CLEAR 233 | // @return none 234 | // ************************************************************************************************* 235 | void display_alarm(u8 line, u8 update) 236 | { 237 | u8 hour12; 238 | 239 | if (update == DISPLAY_LINE_UPDATE_FULL) 240 | { 241 | if (sys.flag.use_metric_units) 242 | { 243 | // Display 24H alarm time "HH:MM" 244 | display_chars(switch_seg(line, LCD_SEG_L1_3_2, 245 | LCD_SEG_L2_3_2), int_to_array(sAlarm.hour, 2, 0), SEG_ON); 246 | } 247 | else 248 | { 249 | // Display 12H alarm time "HH:MM" + AM/PM 250 | hour12 = convert_hour_to_12H_format(sAlarm.hour); 251 | display_chars(switch_seg(line, LCD_SEG_L1_3_2, 252 | LCD_SEG_L2_3_2), int_to_array(hour12, 2, 0), SEG_ON); 253 | 254 | // Display AM/PM symbol 255 | display_am_pm_symbol(sAlarm.hour); 256 | } 257 | display_chars(switch_seg(line, LCD_SEG_L1_1_0, 258 | LCD_SEG_L2_1_0), int_to_array(sAlarm.minute, 2, 0), SEG_ON); 259 | display_symbol(switch_seg(line, LCD_SEG_L1_COL, LCD_SEG_L2_COL0), SEG_ON); 260 | 261 | // Show blinking alarm icon 262 | display_symbol(LCD_ICON_ALARM, SEG_ON_BLINK_ON); 263 | } 264 | else if (update == DISPLAY_LINE_CLEAR) 265 | { 266 | // Clean up function-specific segments before leaving function 267 | display_symbol(LCD_SYMB_AM, SEG_OFF); 268 | 269 | // Clear / set alarm icon 270 | if (sAlarm.state == ALARM_DISABLED) 271 | { 272 | display_symbol(LCD_ICON_ALARM, SEG_OFF_BLINK_OFF); 273 | } 274 | else 275 | { 276 | display_symbol(LCD_ICON_ALARM, SEG_ON_BLINK_OFF); 277 | } 278 | } 279 | } 280 | 281 | -------------------------------------------------------------------------------- /logic/user.c: -------------------------------------------------------------------------------- 1 | // ************************************************************************************************* 2 | // 3 | // Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | // 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions 8 | // are met: 9 | // 10 | // Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // 13 | // Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the 16 | // distribution. 17 | // 18 | // Neither the name of Texas Instruments Incorporated nor the names of 19 | // its contributors may be used to endorse or promote products derived 20 | // from this software without specific prior written permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | // 34 | // ************************************************************************************************* 35 | // Several user functions. 36 | // ************************************************************************************************* 37 | 38 | // ************************************************************************************************* 39 | // Include section 40 | 41 | // system 42 | #include "project.h" 43 | 44 | // driver 45 | #include "display.h" 46 | #include "buzzer.h" 47 | #include "ports.h" 48 | 49 | // logic 50 | #include "menu.h" 51 | #include "date.h" 52 | #include "clock.h" 53 | #include "user.h" 54 | #include "stopwatch.h" 55 | 56 | // ************************************************************************************************* 57 | // Prototypes section 58 | 59 | // ************************************************************************************************* 60 | // Defines section 61 | 62 | // ************************************************************************************************* 63 | // Global Variable section 64 | 65 | // ************************************************************************************************* 66 | // Extern section 67 | extern void idle_loop(void); 68 | 69 | // ************************************************************************************************* 70 | // @fn dummy 71 | // @brief Dummy direct function. 72 | // @param u8 line LINE1, LINE2 73 | // @return none 74 | // ************************************************************************************************* 75 | void dummy(u8 line) 76 | { 77 | } 78 | 79 | // ************************************************************************************************* 80 | // @fn set_value 81 | // @brief Generic value setting routine 82 | // @param s32 * value Pointer to value to 83 | // set 84 | // u8digits 85 | // Number of digits 86 | // u8 blanks 87 | // Number of whitespaces before first valid 88 | // digit 89 | // s32 limitLow Lower limit 90 | // of value 91 | // s32 limitHigh Upper limit 92 | // of value 93 | // u16 mode 94 | // u8 segments 95 | // Segments where value should be drawn 96 | // fptr_setValue_display_function1 Value-specific display 97 | // routine 98 | // @return none 99 | // ************************************************************************************************* 100 | void set_value(s32 * value, u8 digits, u8 blanks, s32 limitLow, s32 limitHigh, u16 mode, 101 | u8 segments, 102 | void (*fptr_setValue_display_function1)(u8 segments, u32 value, u8 digits, 103 | u8 blanks)) 104 | { 105 | u8 update; 106 | s16 stepValue = 1; 107 | u8 doRound = 0; 108 | u8 stopwatch_state; 109 | u32 val; 110 | 111 | // Clear button flags 112 | button.all_flags = 0; 113 | 114 | // Clear blink memory 115 | clear_blink_mem(); 116 | 117 | // For safety only - buzzer on/off and button_repeat share same IRQ 118 | stop_buzzer(); 119 | 120 | // Disable stopwatch display update while function is active 121 | stopwatch_state = sStopwatch.state; 122 | sStopwatch.state = STOPWATCH_HIDE; 123 | 124 | // Init step size and repeat counter 125 | sButton.repeats = 0; 126 | 127 | // Initial display update 128 | update = 1; 129 | 130 | // Turn on 200ms button repeat function 131 | button_repeat_on(200); 132 | 133 | // Start blinking with with 2Hz 134 | set_blink_rate(BIT6 + BIT5); 135 | 136 | // Value set loop 137 | while (1) 138 | { 139 | // Idle timeout: exit function 140 | if (sys.flag.idle_timeout) 141 | break; 142 | 143 | // Button STAR (short) button: exit function 144 | if (button.flag.star) 145 | break; 146 | 147 | // NUM button: exit function and goto to next value (if available) 148 | if (button.flag.num) 149 | { 150 | if ((mode & SETVALUE_NEXT_VALUE) == SETVALUE_NEXT_VALUE) 151 | break; 152 | } 153 | 154 | // UP button: increase value 155 | if (button.flag.up) 156 | { 157 | // Increase value 158 | *value = *value + stepValue; 159 | 160 | // Check value limits 161 | if (*value > limitHigh) 162 | { 163 | // Check if value can roll over, else stick to limit 164 | if ((mode & SETVALUE_ROLLOVER_VALUE) == SETVALUE_ROLLOVER_VALUE) 165 | *value = limitLow; 166 | else 167 | *value = limitHigh; 168 | 169 | // Reset step size to default 170 | stepValue = 1; 171 | } 172 | 173 | // Trigger display update 174 | update = 1; 175 | 176 | // Clear button flag 177 | button.flag.up = 0; 178 | } 179 | 180 | // DOWN button: decrease value 181 | if (button.flag.down) 182 | { 183 | // Decrease value 184 | *value = *value - stepValue; 185 | 186 | // Check value limits 187 | if (*value < limitLow) 188 | { 189 | // Check if value can roll over, else stick to limit 190 | if ((mode & SETVALUE_ROLLOVER_VALUE) == SETVALUE_ROLLOVER_VALUE) 191 | *value = limitHigh; 192 | else 193 | *value = limitLow; 194 | 195 | // Reset step size to default 196 | stepValue = 1; 197 | } 198 | 199 | // Trigger display update 200 | update = 1; 201 | 202 | // Clear button flag 203 | button.flag.down = 0; 204 | } 205 | 206 | // When fast mode is enabled, increase step size if Sx button is continuously 207 | if ((mode & SETVALUE_FAST_MODE) == SETVALUE_FAST_MODE) 208 | { 209 | switch (sButton.repeats) 210 | { 211 | case 0: 212 | stepValue = 1; 213 | doRound = 0; 214 | break; 215 | case 10: 216 | case -10: 217 | stepValue = 10; 218 | doRound = 1; 219 | break; 220 | case 20: 221 | case -20: 222 | stepValue = 100; 223 | doRound = 1; 224 | break; 225 | case 30: 226 | case -30: 227 | stepValue = 1000; 228 | doRound = 1; 229 | break; 230 | } 231 | 232 | // Round value to avoid odd numbers on display 233 | if (stepValue != 1 && doRound == 1) 234 | { 235 | *value -= *value % stepValue; 236 | doRound = 0; 237 | } 238 | } 239 | 240 | // Update display when there is new data 241 | if (update) 242 | { 243 | // Display up or down arrow according to sign of value 244 | if ((mode & SETVALUE_DISPLAY_ARROWS) == SETVALUE_DISPLAY_ARROWS) 245 | { 246 | if (*value >= 0) 247 | { 248 | display_symbol(LCD_SYMB_ARROW_UP, SEG_ON); 249 | display_symbol(LCD_SYMB_ARROW_DOWN, SEG_OFF); 250 | val = *value; 251 | } 252 | else 253 | { 254 | display_symbol(LCD_SYMB_ARROW_UP, SEG_OFF); 255 | display_symbol(LCD_SYMB_ARROW_DOWN, SEG_ON); 256 | val = *value * (-1); 257 | } 258 | } 259 | else 260 | { 261 | val = *value; 262 | } 263 | 264 | // Display function can either display value directly, modify value before displaying 265 | // or display a string referenced by the value 266 | fptr_setValue_display_function1(segments, val, digits, blanks); 267 | 268 | // Clear update flag 269 | update = 0; 270 | } 271 | 272 | // Call idle loop to serve background tasks 273 | idle_loop(); 274 | 275 | } 276 | 277 | // Clear up and down arrows 278 | display_symbol(LCD_SYMB_ARROW_UP, SEG_OFF); 279 | display_symbol(LCD_SYMB_ARROW_DOWN, SEG_OFF); 280 | 281 | // Set blinking rate to 1Hz and stop 282 | set_blink_rate(BIT7 + BIT6 + BIT5); 283 | clear_blink_mem(); 284 | 285 | // Turn off button repeat function 286 | button_repeat_off(); 287 | 288 | // Enable stopwatch display updates again 289 | sStopwatch.state = stopwatch_state; 290 | } 291 | 292 | --------------------------------------------------------------------------------