Browse Source

Initial commit:

This port consists of the following:
0) All places where I modified the original code
(hopefully) are marked with my initials PFS or pfs.
The only actual code changes were to write four
functions to replace the intrinsic functions used
by TI and IAR.
1) bluerobin code had to be elimiated because
mspgcc cannot link to the provided bluerobin library
and the source code is not available.
2) four intrinsic functions had to be written.
As of 2010-06-13 they are untested and couple of
them probably don't work yet.
3) All compiler specific areas what accommodated
IAR and CCS were enhanced to accommodate MSPgcc4
4) The Simpliciti *.dat files were converted to *.h files
fertito
unknown 12 years ago
commit
2daf978279
  1. 473
      bluerobin/bm.h
  2. 206
      driver/adc12.c
  3. 69
      driver/adc12.h
  4. 234
      driver/buzzer.c
  5. 100
      driver/buzzer.h
  6. 570
      driver/display.c
  7. 348
      driver/display.h
  8. 224
      driver/display1.c
  9. 68
      driver/pmm.c
  10. 42
      driver/pmm.h
  11. 437
      driver/ports.c
  12. 121
      driver/ports.h
  13. 205
      driver/radio.c
  14. 48
      driver/radio.h
  15. 239
      driver/rf1a.c
  16. 20
      driver/rf1a.h
  17. 544
      driver/timer.c
  18. 75
      driver/timer.h
  19. 356
      driver/vti_as.c
  20. 112
      driver/vti_as.h
  21. 553
      driver/vti_ps.c
  22. 104
      driver/vti_ps.h
  23. 718
      eZChronos.c
  24. 21
      even_in_range.s
  25. 141
      include/project.h
  26. 55
      intrinsics.c
  27. 27
      intrinsics.h
  28. 75
      logic/MYsimpliciti.c
  29. 276
      logic/acceleration.c
  30. 92
      logic/acceleration.h
  31. 294
      logic/alarm.c
  32. 85
      logic/alarm.h
  33. 428
      logic/altitude.c
  34. 94
      logic/altitude.h
  35. 196
      logic/battery.c
  36. 90
      logic/battery.h
  37. 427
      logic/clock.c
  38. 85
      logic/clock.h
  39. 384
      logic/date.c
  40. 73
      logic/date.h
  41. 271
      logic/menu.c
  42. 95
      logic/menu.h
  43. 104
      logic/rfbsl.c
  44. 52
      logic/rfbsl.h
  45. 630
      logic/rfsimpliciti.c
  46. 98
      logic/rfsimpliciti.h
  47. 440
      logic/stopwatch.c
  48. 95
      logic/stopwatch.h
  49. 332
      logic/temperature.c
  50. 78
      logic/temperature.h
  51. 292
      logic/test.c
  52. 45
      logic/test.h
  53. 269
      logic/user.c
  54. 57
      logic/user.h
  55. 51
      makefile
  56. 264
      simpliciti/Applications/application/End_Device/main_ED_BM.c
  57. 81
      simpliciti/Applications/configuration/End Device/smpl_config.dat
  58. 85
      simpliciti/Applications/configuration/smpl_config.h
  59. 80
      simpliciti/Applications/configuration/smpl_nwk_config.dat
  60. 17
      simpliciti/Applications/configuration/smpl_nwk_config.h
  61. 289
      simpliciti/Components/bsp/boards/CC430EM/bsp_board.c
  62. 83
      simpliciti/Components/bsp/boards/CC430EM/bsp_board_defs.h
  63. 91
      simpliciti/Components/bsp/boards/CC430EM/bsp_button_defs.h
  64. 47
      simpliciti/Components/bsp/boards/CC430EM/bsp_config.h
  65. 54
      simpliciti/Components/bsp/boards/CC430EM/bsp_driver_defs.h
  66. 88
      simpliciti/Components/bsp/boards/CC430EM/bsp_drivers.c
  67. 81
      simpliciti/Components/bsp/boards/CC430EM/bsp_external/mrfi_board_defs.h
  68. 97
      simpliciti/Components/bsp/boards/CC430EM/bsp_led_defs.h
  69. 101
      simpliciti/Components/bsp/bsp.c
  70. 183
      simpliciti/Components/bsp/bsp.h
  71. 79
      simpliciti/Components/bsp/bsp_macros.h
  72. 90
      simpliciti/Components/bsp/drivers/bsp_buttons.h
  73. 133
      simpliciti/Components/bsp/drivers/bsp_leds.h
  74. 97
      simpliciti/Components/bsp/drivers/code/bsp_buttons.c
  75. 203
      simpliciti/Components/bsp/drivers/code/bsp_generic_buttons.h
  76. 278
      simpliciti/Components/bsp/drivers/code/bsp_generic_leds.h
  77. 107
      simpliciti/Components/bsp/drivers/code/bsp_leds.c
  78. 175
      simpliciti/Components/bsp/mcus/bsp_msp430_defs.h
  79. 87
      simpliciti/Components/mrfi/mrfi.c
  80. 186
      simpliciti/Components/mrfi/mrfi.h
  81. 226
      simpliciti/Components/mrfi/mrfi_defs.h
  82. 1778
      simpliciti/Components/mrfi/radios/family5/mrfi_radio.c
  83. 374
      simpliciti/Components/mrfi/radios/family5/mrfi_radio_interface.c
  84. 150
      simpliciti/Components/mrfi/radios/family5/mrfi_radio_interface.h
  85. 130
      simpliciti/Components/mrfi/smartrf/CC1101/smartrf_CC1101.h
  86. 164
      simpliciti/Components/mrfi/smartrf/CC430/smartrf_CC430.h
  87. 1078
      simpliciti/Components/nwk/nwk.c
  88. 161
      simpliciti/Components/nwk/nwk.h
  89. 417
      simpliciti/Components/nwk/nwk_QMgmt.c
  90. 53
      simpliciti/Components/nwk/nwk_QMgmt.h
  91. 858
      simpliciti/Components/nwk/nwk_api.c
  92. 56
      simpliciti/Components/nwk/nwk_api.h
  93. 53
      simpliciti/Components/nwk/nwk_app.h
  94. 948
      simpliciti/Components/nwk/nwk_frame.c
  95. 151
      simpliciti/Components/nwk/nwk_frame.h
  96. 258
      simpliciti/Components/nwk/nwk_globals.c
  97. 51
      simpliciti/Components/nwk/nwk_globals.h
  98. 344
      simpliciti/Components/nwk/nwk_types.h
  99. 619
      simpliciti/Components/nwk_applications/nwk_freq.c
  100. 72
      simpliciti/Components/nwk_applications/nwk_freq.h
  101. Some files were not shown because too many files have changed in this diff Show More

473
bluerobin/bm.h

@ -0,0 +1,473 @@
// *************************************************************************************************
//
// Copyright 2009 BM innovations GmbH (www.bm-innovations.com), all rights reserved.
//
// This trial version of the "BlueRobin(TM) receiver library for the Texas Instruments
// CC430 SoC" may be used for non-profit non-commercial purposes only. If you want to use
// BlueRobin(TM) in a commercial project, please contact the copyright holder for a
// separate license agreement.
//
// By using this trial version of the "BlueRobin(TM) receiver library for the Texas Instruments
// CC430 SoC", you implicitly agree that you will not modify, adapt, disassemble, decompile,
// reverse engineer, translate or otherwise attempt to discover the source code of the
// "BlueRobin(TM) receiver library for the Texas Instruments CC430 SoC".
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// *************************************************************************************************
// Standard definitions, have to be included in every source and header file.
// *************************************************************************************************
#ifndef __BM_H
#define __BM_H
#if (defined __IAR_SYSTEMS_ASM) || (defined __IAR_SYSTEMS_ASM__)
#define _ASSEMBLER_USED_
#endif
#ifndef _ASSEMBLER_USED_
#include <stddef.h>
#endif
#ifndef FALSE
// the classic false
#define FALSE (0 == 1)
#endif
#ifndef TRUE
// the classic true
#define TRUE (1 == 1)
#endif
#ifndef USE_RAW_ATTR
// per default this feature is disabled
#define USE_RAW_ATTR FALSE
#endif
// *************************************************************************************************
// First Section: Basic Data Types
// *************************************************************************************************
// Fundamental #definitions
// CPU target idents are used for target dependent compilations
// Texas Instruments MSP430
#define _TI_MSP430_ (16)
// Find the currently running compiler
// and make the related #define's
// _IAR_TID_ target ID from IAR compilers
// _CPU_TID_ remap to enum of processor target numbers
// _CPU_8BIT_INT_ type for 8 bit int
// _CPU_16BIT_INT_ type for 16 bit int
// _CPU_32BIT_INT_ type for 32 bit int
// _CPU_32BIT_FLOAT_ type for 32 bit float
// _CPU_64BIT_FLOAT_ type for 64 bit float
// INTERRUPT declares an interrupt service routine without an entry in the vector table
// ISR(vector) declares an interrupt service routine which is added in vector table at offset vector
// MONITOR declares a function atomic
// INTERRUPTS_ENABLE remap to the intrinsic for enable interrupts
// INTERRUPTS_DISABLE remap to the intrinsic for disable interrupts
// NO_OPERATION remap to the intrinsic for no operation
// _CPU_DIRECTION_OUT_1_ if TRUE the direction register indicates with an 1: direction is output
// _CPU_EDGE_HIGH_LOW_1_ if TRUE the edge select register indicates with an 1: trigger on high low
// NO_INIT declare a variable as not initialized
// INLINE_FUNC declare a function as inline for release builds
#if ((defined __IAR_SYSTEMS_ICC) || (defined __IAR_SYSTEMS_ASM)) && (__IAR_SYSTEMS_ICC__ < 2)
// Found IAR Compiler with classic IAR frontend
#ifndef _IAR_TID_
#define _IAR_TID_ ((__TID__ >> 8) & 0x7f)
#endif
#define INTERRUPT interrupt
#define ISR(vector) interrupt [(vector)]
#define MONITOR monitor
#if ((_IAR_TID_) == 43)
// Found Texas Instruments MSP430 CPU
#define _CPU_TID_ _TI_MSP430_
#define _CPU_DIRECTION_OUT_1_ TRUE
#define _CPU_EDGE_HIGH_LOW_1_ TRUE
#define INTERRUPTS_ENABLE() _EINT()
// WA for HW bug, add a NOP
#define INTERRUPTS_DISABLE() { _DINT(); _NOP(); }
#define NO_OPERATION() _NOP()
#else
#error "Unknown IAR Compiler, the file bm.h has to be expanded !"
#endif
#elif defined __IAR_SYSTEMS_ICC__
// Found IAR Compiler with EDG frontend
#define _IAR_TID_ ((__TID__ >> 8) & 0x7f)
#if USE_RAW_ATTR == TRUE
// Use the raw attribute in ISR's
#define _RAW __raw
#else
// Empty define RAW as it is not used
#define _RAW
#endif
#define INTERRUPT _RAW __interrupt
#define MONITOR __monitor
#define NO_INIT __no_init
#define INTERRUPTS_ENABLE() __enable_interrupt()
#define INTERRUPTS_DISABLE() __disable_interrupt()
#define NO_OPERATION() __no_operation()
#ifndef DEBUG
// Force inlining of function in release builds
#define INLINE_FUNC PRAGMA(inline=forced)
#else
// Do not force inlining of function in debug builds
#define INLINE_FUNC
#endif
#if (!defined CODECHECK) && (!defined __DA_C__)
// Define to a new way of using #pragmas in preprocessor
#define PRAGMA(x) _Pragma(#x)
#define ISR(x) PRAGMA(vector = (x)) INTERRUPT
#endif
#if ((_IAR_TID_) == 43)
// Found Texas Instruments MSP430 CPU (V2)
#define _CPU_TID_ _TI_MSP430_
#define _CPU_DIRECTION_OUT_1_ TRUE
#define _CPU_EDGE_HIGH_LOW_1_ TRUE
#define _CPU_64BIT_INT_ long long
#if __VER__ < 220
// WA for HW bug, add a nop after DINT, Compiler has a bugfix since version 2.20
#undef INTERRUPTS_DISABLE
#define INTERRUPTS_DISABLE() { __disable_interrupt(); __no_operation(); }
#endif
#else
#error "Unknown new IAR Compiler, the file bm.h has to be expanded !"
#endif
#elif defined __CCE__
// Found CCE Compiler
#define INTERRUPT __interrupt
#define MONITOR // __monitor
#define NO_INIT __no_init
#define INTERRUPTS_ENABLE() __enable_interrupt()
#define INTERRUPTS_DISABLE() __disable_interrupt()
#define NO_OPERATION() __no_operation()
#ifndef DEBUG
// Force inlining of function in release builds
#define INLINE_FUNC PRAGMA(inline=forced)
#else
// Do not force inlining of function in debug builds
#define INLINE_FUNC
#endif
// Found Texas Instruments MSP430 CPU (V2)
#define _CPU_TID_ _TI_MSP430_
#define _CPU_DIRECTION_OUT_1_ TRUE
#define _CPU_EDGE_HIGH_LOW_1_ TRUE
//#define _CPU_64BIT_INT_ long long
// #endif
// PFS added
#elif defined __MSP430__
// Found MSP430 Compiler
// PFS #define INTERRUPT interrupt
#define ISR(vector) interrupt(vector)
#define MONITOR // __monitor
#define NO_INIT _reset_vector__ // PFS removed __no_init
#define INTERRUPTS_ENABLE() _EINT() //PFS or eint()
#define INTERRUPTS_DISABLE() _DINT() // PFS or dint()
#define NO_OPERATION() // PFS __no_operation()
#ifndef DEBUG
// Force inlining of function in release builds
#define INLINE_FUNC PRAGMA(inline=forced)
#else
// Do not force inlining of function in debug builds
#define INLINE_FUNC
#endif
// Found Texas Instruments MSP430 CPU (V2)
#define _CPU_TID_ _TI_MSP430_
#define _CPU_DIRECTION_OUT_1_ TRUE
#define _CPU_EDGE_HIGH_LOW_1_ TRUE
//#define _CPU_64BIT_INT_ long long
// #endif
#else
#error "Unknown Compiler, the file bm.h has to be expanded !"
#endif
#ifndef _ASSEMBLER_USED_
// Get the limits to autodetect the size of integral types
#include <limits.h>
// Get floats to autodetect the size of float types
#include <float.h>
// ***********************************************************************************************
//
// Common basic data types
//
// ***********************************************************************************************
#if UCHAR_MAX == 0xFFu
#define _CPU_8BIT_INT_ char
#else
#error "unable to get size of u8 automatically"
#endif
#if USHRT_MAX == 0xFFFFu
#define _CPU_16BIT_INT_ short
#elif UINT_MAX == 0xFFFFu
#define _CPU_16BIT_INT_ int
#else
#error "unable to get size of u16 automatically"
#endif
#if USHRT_MAX == 0xFFFFFFFFu
#define _CPU_32BIT_INT_ short
#elif UINT_MAX == 0xFFFFFFFFu
#define _CPU_32BIT_INT_ int
#elif ULONG_MAX == 0xFFFFFFFFu
#define _CPU_32BIT_INT_ long
#else
#error "unable to get size of u32 automatically"
#endif
#ifdef __IAR_SYSTEMS_ICC__
#if __IAR_SYSTEMS_ICC__ > 1
#define _CPU_32BIT_FLOAT_ float
#if __DOUBLE_SIZE__ == 8
#define _CPU_64BIT_FLOAT_ double
#endif
#endif
#endif
#ifndef _CPU_32BIT_FLOAT_
#if FLT_MANT_DIG == 24
#define _CPU_32BIT_FLOAT_ float
#elif DBL_MANT_DIG == 24
#define _CPU_32BIT_FLOAT_ double
#else
#error "unable to get size of f32 automatically"
#endif
#if DBL_MANT_DIG == 53
#define _CPU_64BIT_FLOAT_ double
#endif
#endif
// ***********************************************************************************************
//
// Following lines #typedef the basic data types in a compiler independent way.
//
// ***********************************************************************************************
#ifdef _CPU_8BIT_INT_
// unsigned 8 bit
typedef unsigned _CPU_8BIT_INT_ u8 ;
// unsigned 8 bit max value
#define U8_MAX (0xFFU)
// signed 8 bit max value
typedef signed _CPU_8BIT_INT_ s8 ;
// signed 8 bit min value
#define S8_MIN (-127 - 1)
// signed 8 bit max value
#define S8_MAX (127)
#endif
#ifdef _CPU_16BIT_INT_
// unsigned 16 bit
typedef unsigned _CPU_16BIT_INT_ u16 ;
// unsigned 16 bit max value
#define U16_MAX (0xFFFFU)
// signed 16 bit
typedef signed _CPU_16BIT_INT_ s16 ;
// signed 16 bit min value
#define S16_MIN (-32767 - 1)
// signed 16 bit max value
#define S16_MAX (32767)
#endif
#ifdef _CPU_32BIT_INT_
// unsigned 32 bit
typedef unsigned _CPU_32BIT_INT_ u32 ;
// unsigned 32 bit max value
#define U32_MAX (0xFFFFFFFFUL)
// signed 32 bit
typedef signed _CPU_32BIT_INT_ s32 ;
// signed 32 bit min value
#define S32_MIN (-2147483647L - 1L)
// signed 32 bit max value
#define S32_MAX (2147483647L)
#endif
#ifdef _CPU_64BIT_INT_
// unsigned 64 bit
typedef unsigned _CPU_64BIT_INT_ u64 ;
// signed 64 bit
typedef signed _CPU_64BIT_INT_ s64 ;
#endif
#ifdef _CPU_32BIT_FLOAT_
// float 32 bit
typedef _CPU_32BIT_FLOAT_ f32 ;
// number of digits in mantissa of f32
#define F32_MANT_DIG (24)
// epsilon for f32
#define F32_EPSILON (1.192092896e-07)
// number of digits of precision of f32
#define F32_DIG (6)
// exponent min of f32
#define F32_MIN_EXP (-125)
// min positive value of f32
#define F32_MIN (1.175494351e-38)
// decimal exponent min of f32
#define F32_MIN_10_EXP (-37)
// exponent max of f32
#define F32_MAX_EXP (128)
// max value of f32
#define F32_MAX (3.402823466e+38)
// decimal exponent max of f32
#define F32_MAX_10_EXP (38)
#endif
#ifdef _CPU_64BIT_FLOAT_
// float 64 bit
typedef _CPU_64BIT_FLOAT_ f64 ;
// number of digits in mantissa of f64
#define F64_MANT_DIG (53)
// epsilon for f64
#define F64_EPSILON (2.2204460492503131e-016)
// number of digits of precision of f64
#define F64_DIG (15)
// exponent min of f64
#define F64_MIN_EXP (-1021)
// min positive value of f64
#define F64_MIN (2.2250738585072014e-308)
// decimal exponent min of f64
#define F64_MIN_10_EXP (-307)
// exponent max of f64
#define F64_MAX_EXP (1024)
// max value of f64
#define F64_MAX (1.7976931348623158e+308)
// decimal exponent max of f64
#define F64_MAX_10_EXP (308)
#endif
typedef unsigned char BYTE;
typedef unsigned int WORD;
typedef unsigned long DWORD;
#endif // _ASSMEBLER_USED_
// A macro that calculates the number of bits of a given type
#ifndef BITSIZEOF
#define BITSIZEOF(type) (sizeof(type) * CHAR_BIT)
#endif
/* A macro that generates a bit mask according to a given bit number.
* Example:
* - BIT(0) expands to 1 (== 0x01)
* - BIT(3) expands to 8 (== 0x08)
*/
#define BIT(x) (1uL << (x))
/* A macro that generates a bit mask according to a given bit number with a cast to type.
* The difference to BIT(X) is the additional type argument T that is used to cast the type of the
* constant 1 and the type of the result as well.
* Example:
* - BIT_T(u8,0) expands to (u8)1 (== 0x01)
* - BIT_T(u32,3) expands to (u32)8 (== 0x08L)
*/
#define BIT_T(t, x) ((t)((t)1 << (x)))
/* A macro to calculate the position of the highest bit.
* The result is same as LOG2 in case only one bit is set. Use with constant values only because
* of code size.
*/
#define BIT_HIGHEST(Input_u32) ( \
( (Input_u32) & BIT(31) ) ? 31 : ( \
( (Input_u32) & BIT(30) ) ? 30 : ( \
( (Input_u32) & BIT(29) ) ? 29 : ( \
( (Input_u32) & BIT(28) ) ? 28 : ( \
( (Input_u32) & BIT(27) ) ? 27 : ( \
( (Input_u32) & BIT(26) ) ? 26 : ( \
( (Input_u32) & BIT(25) ) ? 25 : ( \
( (Input_u32) & BIT(24) ) ? 24 : ( \
( (Input_u32) & BIT(23) ) ? 23 : ( \
( (Input_u32) & BIT(22) ) ? 22 : ( \
( (Input_u32) & BIT(21) ) ? 21 : ( \
( (Input_u32) & BIT(20) ) ? 20 : ( \
( (Input_u32) & BIT(19) ) ? 19 : ( \
( (Input_u32) & BIT(18) ) ? 18 : ( \
( (Input_u32) & BIT(17) ) ? 17 : ( \
( (Input_u32) & BIT(16) ) ? 16 : ( \
( (Input_u32) & BIT(15) ) ? 15 : ( \
( (Input_u32) & BIT(14) ) ? 14 : ( \
( (Input_u32) & BIT(13) ) ? 13 : ( \
( (Input_u32) & BIT(12) ) ? 12 : ( \
( (Input_u32) & BIT(11) ) ? 11 : ( \
( (Input_u32) & BIT(10) ) ? 10 : ( \
( (Input_u32) & BIT( 9) ) ? 9 : ( \
( (Input_u32) & BIT( 8) ) ? 8 : ( \
( (Input_u32) & BIT( 7) ) ? 7 : ( \
( (Input_u32) & BIT( 6) ) ? 6 : ( \
( (Input_u32) & BIT( 5) ) ? 5 : ( \
( (Input_u32) & BIT( 4) ) ? 4 : ( \
( (Input_u32) & BIT( 3) ) ? 3 : ( \
( (Input_u32) & BIT( 2) ) ? 2 : ( \
( (Input_u32) & BIT( 1) ) ? 1 : ( \
( (Input_u32) & BIT( 0) ) ? 0 : -1uL ))))))))))))))))))))))))))))))))
#ifndef MONITOR
#define MONITOR
#endif
#ifndef NO_INIT
#define NO_INIT
#endif
#ifndef INTERRUPT
#define INTERRUPT
#endif
#ifndef ISR
#define ISR(ignore)
#endif
#ifndef INLINE_FUNC
#define INLINE_FUNC
#endif
#ifndef INTERRUPTS_ENABLE
#define INTERRUPTS_ENABLE()
#endif
#ifndef INTERRUPTS_DISABLE
#define INTERRUPTS_DISABLE()
#endif
#endif // __BM_H

206
driver/adc12.c

@ -0,0 +1,206 @@
// *************************************************************************************************
//
// Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// *************************************************************************************************
// ADC12 functions.
// *************************************************************************************************
// *************************************************************************************************
// Include section
// system
#include <project.h>
// driver
#include "adc12.h"
#include "timer.h"
// *************************************************************************************************
// Prototypes section
// *************************************************************************************************
// Defines section
// *************************************************************************************************
// Global Variable section
u16 adc12_result;
u8 adc12_data_ready;
// *************************************************************************************************
// Extern section
//
//
//// *************************************************************************************************
//// @fn adc12_single_conversion
//// @brief Init ADC12. Do single conversion. Turn off ADC12.
//// @param none
//// @return none
//// *************************************************************************************************
//u16 adc12_single_conversion(u16 ref_v, u16 adc12_sht, u16 adc12_ssel, u16 adc12_vref, u16 adc12_channel, u16 adc12_conv_delay)
//{
// u16 adc12_result;
//
// // Set REF reference voltage to 1.5V (temperature) or 2.5V (battery)
// REFCTL0 |= REFMSTR + REFON + ref_v;
//
// // Initialize ADC12
// ADC12CTL0 = ADC12ON + adc12_sht;
// ADC12CTL1 = ADC12SHP + adc12_ssel; // Use sampling timer, ADC12CLK = ACLK
// ADC12CTL2 = ADC12RES_2 + ADC12SR; // 12-bit mode, 50ksps
// ADC12MCTL0 = adc12_vref + adc12_channel; // Set reference, set input channel
//
// // Wait until ADC12 reference voltage has settled
// Timer0_A4_Delay(CONV_US_TO_TICKS(ADC12_REFERENCE_SETTLING_TIME_USEC));
//
// // Start conversion
// ADC12CTL0 |= ADC12ENC | ADC12SC;
//
// // Wait until ADC12 has finished
// Timer0_A4_Delay(CONV_US_TO_TICKS(adc12_conv_delay));
// while ((ADC12CTL1 & ADC12BUSY) == ADC12BUSY);
//
// // Store measurement result
// adc12_result = ADC12MEM0;
//
// // Shut down ADC12
// ADC12CTL0 &= ~(ADC12ENC | ADC12SC);
// ADC12CTL0 &= ~ADC12ON;
//
// // Shut down reference voltage
// REFCTL0 &= ~(REFMSTR + REFVSEL_2 + REFON);
//
// // Return ADC result
// return (adc12_result);
//}
// *************************************************************************************************
// @fn adc12_single_conversion
// @brief Init ADC12. Do single conversion. Turn off ADC12.
// @param none
// @return none
// *************************************************************************************************
u16 adc12_single_conversion(u16 ref, u16 sht, u16 channel)
{
// Initialize the shared reference module
REFCTL0 |= REFMSTR + ref + REFON; // Enable internal reference (1.5V or 2.5V)
// Initialize ADC12_A
ADC12CTL0 = sht + ADC12ON; // Set sample time
ADC12CTL1 = ADC12SHP; // Enable sample timer
ADC12MCTL0 = ADC12SREF_1 + channel; // ADC input channel
ADC12IE = 0x001; // ADC_IFG upon conv result-ADCMEMO
// Wait 2 ticks (66us) to allow internal reference to settle
Timer0_A4_Delay(2);
// Start ADC12
ADC12CTL0 |= ADC12ENC;
// Clear data ready flag
adc12_data_ready = 0;
// Sampling and conversion start
ADC12CTL0 |= ADC12SC;
// Wait until ADC12 has finished
Timer0_A4_Delay(5);
while (!adc12_data_ready);
// Shut down ADC12
ADC12CTL0 &= ~(ADC12ENC | ADC12SC | sht);
ADC12CTL0 &= ~ADC12ON;
// Shut down reference voltage
REFCTL0 &= ~(REFMSTR + ref + REFON);
ADC12IE = 0;
// Return ADC result
return (adc12_result);
}
// *************************************************************************************************
// @fn ADC12ISR
// @brief Store ADC12 conversion result. Set flag to indicate data ready.
// @param none
// @return none
// *************************************************************************************************
//pfs wrapped the following to accommodate mspgcc compiler
#ifdef __GNUC__
#include <signal.h>
interrupt (ADC12_VECTOR) ADC12ISR (void)
#else
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
#endif
{
switch(__even_in_range(ADC12IV,34))
{
case 0: break; // Vector 0: No interrupt
case 2: break; // Vector 2: ADC overflow
case 4: break; // Vector 4: ADC timing overflow
case 6: // Vector 6: ADC12IFG0
adc12_result = ADC12MEM0; // Move results, IFG is cleared
adc12_data_ready = 1;
_BIC_SR_IRQ(LPM3_bits); // Exit active CPU
break;
case 8: break; // Vector 8: ADC12IFG1
case 10: break; // Vector 10: ADC12IFG2
case 12: break; // Vector 12: ADC12IFG3
case 14: break; // Vector 14: ADC12IFG4
case 16: break; // Vector 16: ADC12IFG5
case 18: break; // Vector 18: ADC12IFG6
case 20: break; // Vector 20: ADC12IFG7
case 22: break; // Vector 22: ADC12IFG8
case 24: break; // Vector 24: ADC12IFG9
case 26: break; // Vector 26: ADC12IFG10
case 28: break; // Vector 28: ADC12IFG11
case 30: break; // Vector 30: ADC12IFG12
case 32: break; // Vector 32: ADC12IFG13
case 34: break; // Vector 34: ADC12IFG14
default: break;
}
}

69
driver/adc12.h

@ -0,0 +1,69 @@
// *************************************************************************************************
//
// Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// *************************************************************************************************
#ifndef ADC12_H_
#define ADC12_H_
// *************************************************************************************************
// Include section
// *************************************************************************************************
// Prototypes section
extern u16 adc12_single_conversion(u16 ref, u16 sht, u16 channel);
// *************************************************************************************************
// Defines section
//// Reference settling time
//#define ADC12_REFERENCE_SETTLING_TIME_USEC (4*34u)
//
//// Delay for temperature measurement
//#define ADC12_TEMP_CONVERSION_TIME_USEC (10*34u)
//
//// Delay for battery voltage measurement
//#define ADC12_BATT_CONVERSION_TIME_USEC (10*34u)
// *************************************************************************************************
// Global Variable section
extern u16 adc12_result;
extern u8 adc12_data_ready;
// *************************************************************************************************
// Extern section
#endif /*ADC12_H_*/

234
driver/buzzer.c

@ -0,0 +1,234 @@
// *************************************************************************************************
//
// Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// *************************************************************************************************
// Buzzer functions.
// *************************************************************************************************
// *************************************************************************************************
// Include section
// system
#include "project.h"
// driver
#include "buzzer.h"
#include "timer.h"
#include "display.h"
// logic
#include "alarm.h"
// *************************************************************************************************
// Prototypes section
void toggle_buzzer(void);
void countdown_buzzer(void);
// *************************************************************************************************
// Defines section
// *************************************************************************************************
// Global Variable section
struct buzzer sBuzzer;
// *************************************************************************************************
// Extern section
//extern u16 timer0_A3_ticks_g;
// *************************************************************************************************
// @fn reset_buzzer
// @brief Init buzzer variables
// @param none
// @return none
// *************************************************************************************************
void reset_buzzer(void)
{
sBuzzer.time = 0;
sBuzzer.state = BUZZER_OFF;
}
// *************************************************************************************************
// @fn start_buzzer
// @brief Start buzzer output for a number of cylces
// @param u8 cycles Keep buzzer output for number of cycles
// u16 on_time Output buzzer for "on_time" ACLK ticks
// u16 off_time Do not output buzzer for "off_time" ACLK ticks
// @return none
// *************************************************************************************************
void start_buzzer(u8 cycles, u16 on_time, u16 off_time)
{
// Store new buzzer duration while buzzer is off
if (sBuzzer.time == 0)
{
sBuzzer.time = cycles;
sBuzzer.on_time = on_time;
sBuzzer.off_time = off_time;
// Need to init every time, because SimpliciTI claims same timer
// Reset TA1R, set up mode, TA1 runs from 32768Hz ACLK
TA1CTL = TACLR | MC_1 | TASSEL__ACLK;
// Set PWM frequency
TA1CCR0 = BUZZER_TIMER_STEPS;
// Enable IRQ, set output mode "toggle"
TA1CCTL0 = OUTMOD_4;
// Allow buzzer PWM output on P2.7
P2SEL |= BIT7;
// Activate Timer0_A3 periodic interrupts
fptr_Timer0_A3_function = toggle_buzzer;
Timer0_A3_Start(sBuzzer.on_time);
// Preload timer advance variable
sTimer.timer0_A3_ticks = sBuzzer.off_time;
// Start with buzzer output on
sBuzzer.state = BUZZER_ON_OUTPUT_ENABLED;
}
}
// *************************************************************************************************
// @fn toggle_buzzer
// @brief Keeps track of buzzer on/off duty cycle
// @param none
// @return none
// *************************************************************************************************
void toggle_buzzer(void)
{
// Turn off buzzer
if (sBuzzer.state == BUZZER_ON_OUTPUT_ENABLED)
{
// Stop PWM timer
TA1CTL &= ~(BIT4 | BIT5);
// Reset and disable buzzer PWM output
P2OUT &= ~BIT7;
P2SEL &= ~BIT7;
// Update buzzer state
sBuzzer.state = BUZZER_ON_OUTPUT_DISABLED;
// Reload Timer0_A4 IRQ to restart output
sTimer.timer0_A3_ticks = sBuzzer.on_time;
}
else // Turn on buzzer
{
// Decrement buzzer total cycles
countdown_buzzer();
// Reload Timer0_A4 to stop output if sBuzzer.time > 0
if (sBuzzer.state != BUZZER_OFF)
{
// Reset timer TA1
TA1R = 0;
TA1CTL |= MC_1;
// Enable buzzer PWM output
P2SEL |= BIT7;
// Update buzzer state
sBuzzer.state = BUZZER_ON_OUTPUT_ENABLED;
// Reload Timer0_A4 IRQ to turn off output
sTimer.timer0_A3_ticks = sBuzzer.off_time;
}
}
}
// *************************************************************************************************
// @fn stop_buzzer
// @brief Stop buzzer output
// @param none
// @return none
// *************************************************************************************************
void stop_buzzer(void)
{
// Stop PWM timer
TA1CTL &= ~(BIT4 | BIT5);
// Disable buzzer PWM output
P2OUT &= ~BIT7;
P2SEL &= ~BIT7;
// Clear PWM timer interrupt
TA1CCTL0 &= ~CCIE;
// Disable periodic start/stop interrupts
Timer0_A3_Stop();
// Clear variables
reset_buzzer();
}
// *************************************************************************************************
// @fn is_buzzer
// @brief Check if buzzer is operating
// @param none
// @return u8 1 = Buzzer is operating, 0 = Buzzer is off
// *************************************************************************************************
u8 is_buzzer(void)
{
return (sBuzzer.state != BUZZER_OFF);
}
// *************************************************************************************************
// @fn countdown_buzzer
// @brief Decrement active buzzer time. Turn off buzzer if cycle end reached.
// @param none
// @return none
// *************************************************************************************************
void countdown_buzzer(void)
{
// Stop buzzer when reaching 0 cycles
if (--sBuzzer.time == 0)
{
stop_buzzer();
}
}

100
driver/buzzer.h

@ -0,0 +1,100 @@
// *************************************************************************************************
//
// Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// *************************************************************************************************
#ifndef BUZZER_H_
#define BUZZER_H_
// *************************************************************************************************
// Include section
// *************************************************************************************************
// Prototypes section
extern void reset_buzzer(void);
extern void start_buzzer(u8 cycles, u16 on_time, u16 off_time);
extern void stop_buzzer(void);
extern void toggle_buzzer(void);
extern u8 is_buzzer(void);
extern void countdown_buzzer(void);
// *************************************************************************************************
// Defines section
// Buzzer states
#define BUZZER_OFF (0u)
#define BUZZER_ON_OUTPUT_DISABLED (1u)
#define BUZZER_ON_OUTPUT_ENABLED (2u)
// Buzzer modes
#define BUZZER_MODE_SINGLE (0u)
#define BUZZER_MODE_SINGLE_CONTINUOUS (1u)
#define BUZZER_MODE_DOUBLE_CONTINUOUS (2u)
// Buzzer output signal frequency = 32,768kHz/(BUZZER_TIMER_STEPS+1)/2 = 2.7kHz
#define BUZZER_TIMER_STEPS (5u)
// Buzzer on time
#define BUZZER_ON_TICKS (CONV_MS_TO_TICKS(20))
// Buzzer off time
#define BUZZER_OFF_TICKS (CONV_MS_TO_TICKS(200))
// *************************************************************************************************
// Global Variable section
struct buzzer
{
// Keep output for "time" seconds
u8 time;
// On/off duty
u16 on_time;
u16 off_time;
// Current buzzer output state
u8 state;
};
extern struct buzzer sBuzzer;
// *************************************************************************************************
// Extern section
#endif /*BUZZER_H_*/

570
driver/display.c

@ -0,0 +1,570 @@
// *************************************************************************************************
//
// Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// *************************************************************************************************
// Display functions.
// *************************************************************************************************
// *************************************************************************************************
// Include section
// system
#include <project.h>
#include <string.h>
// driver
#include "display.h"
// logic
#include "clock.h"
#include "user.h"
#include "date.h"
#include "stopwatch.h"
#include "temperature.h"
// *************************************************************************************************
// Prototypes section
void write_lcd_mem(u8 * lcdmem, u8 bits, u8 bitmask, u8 state);
void clear_line(u8 line);
void display_symbol(u8 symbol, u8 mode);
void display_char(u8 segment, u8 chr, u8 mode);
void display_chars(u8 segments, u8 * str, u8 mode);
// *************************************************************************************************
// Defines section
// *************************************************************************************************
// Global Variable section
// Display flags
volatile s_display_flags display;
// Global return string for itoa function
u8 itoa_str[8];
// *************************************************************************************************
// Extern section
extern void (*fptr_lcd_function_line1)(u8 line, u8 update);
extern void (*fptr_lcd_function_line2)(u8 line, u8 update);
// *************************************************************************************************
// @fn lcd_init
// @brief Erase LCD memory. Init LCD peripheral.
// @param none
// @return none
// *************************************************************************************************
void lcd_init(void)
{
// Clear entire display memory
LCDBMEMCTL |= LCDCLRBM + LCDCLRM;
// LCD_FREQ = ACLK/16/8 = 256Hz
// Frame frequency = 256Hz/4 = 64Hz, LCD mux 4, LCD on
LCDBCTL0 = (LCDDIV0 + LCDDIV1 + LCDDIV2 + LCDDIV3) | (LCDPRE0 + LCDPRE1) | LCD4MUX | LCDON;
// LCB_BLK_FREQ = ACLK/8/4096 = 1Hz
LCDBBLKCTL = LCDBLKPRE0 | LCDBLKPRE1 | LCDBLKDIV0 | LCDBLKDIV1 | LCDBLKDIV2 | LCDBLKMOD0;
// I/O to COM outputs
P5SEL |= (BIT5 | BIT6 | BIT7);
P5DIR |= (BIT5 | BIT6 | BIT7);
// Activate LCD output
LCDBPCTL0 = 0xFFFF; // Select LCD segments S0-S15
LCDBPCTL1 = 0x00FF; // Select LCD segments S16-S22
#ifdef USE_LCD_CHARGE_PUMP
// Charge pump voltage generated internally, internal bias (V2-V4) generation
LCDBVCTL = LCDCPEN | VLCD_2_72;
#endif
}
// *************************************************************************************************
// @fn clear_display_all
// @brief Erase LINE1 and LINE2 segments. Clear also function-specific content.
// @param none
// @return none
// *************************************************************************************************
void clear_display_all(void)
{
// Clear generic content
clear_line(LINE1);
clear_line(LINE2);
// Clean up function-specific content
fptr_lcd_function_line1(LINE1, DISPLAY_LINE_CLEAR);
fptr_lcd_function_line2(LINE2, DISPLAY_LINE_CLEAR);
}
// *************************************************************************************************
// @fn clear_display
// @brief Erase LINE1 and LINE2 segments. Keep icons.
// @param none
// @return none
// *************************************************************************************************
void clear_display(void)
{
clear_line(LINE1);
clear_line(LINE2);
}
// *************************************************************************************************
// @fn clear_line
// @brief Erase segments of a given line.
// @param u8 line LINE1, LINE2
// @return none
// *************************************************************************************************
void clear_line(u8 line)
{
display_chars(switch_seg(line, LCD_SEG_L1_3_0, LCD_SEG_L2_5_0), NULL, SEG_OFF);
if (line == LINE1)
{
display_symbol(LCD_SEG_L1_DP1, SEG_OFF);
display_symbol(LCD_SEG_L1_DP0, SEG_OFF);
display_symbol(LCD_SEG_L1_COL, SEG_OFF);
}
else // line == LINE2
{
display_symbol(LCD_SEG_L2_DP, SEG_OFF);
display_symbol(LCD_SEG_L2_COL1, SEG_OFF);
display_symbol(LCD_SEG_L2_COL0, SEG_OFF);
}
}
// *************************************************************************************************
// @fn write_segment
// @brief Write to one or multiple LCD segments
// @param lcdmem Pointer to LCD byte memory
// bits Segments to address
// bitmask Bitmask for particular display item
// mode On, off or blink segments
// @return
// *************************************************************************************************
void write_lcd_mem(u8 * lcdmem, u8 bits, u8 bitmask, u8 state)
{
if (state == SEG_ON)
{
// Clear segments before writing
*lcdmem = (u8)(*lcdmem & ~bitmask);
// Set visible segments
*lcdmem = (u8)(*lcdmem | bits);
}
else if (state == SEG_OFF)
{
// Clear segments
*lcdmem = (u8)(*lcdmem & ~bitmask);
}
else if (state == SEG_ON_BLINK_ON)
{
// Clear visible / blink segments before writing
*lcdmem = (u8)(*lcdmem & ~bitmask);
*(lcdmem+0x20) = (u8)(*(lcdmem+0x20) & ~bitmask);
// Set visible / blink segments
*lcdmem = (u8)(*lcdmem | bits);
*(lcdmem+0x20) = (u8)(*(lcdmem+0x20) | bits);
}
else if (state == SEG_ON_BLINK_OFF)
{
// Clear visible segments before writing
*lcdmem = (u8)(*lcdmem & ~bitmask);
// Set visible segments
*lcdmem = (u8)(*lcdmem | bits);
// Clear blink segments
*(lcdmem+0x20) = (u8)(*(lcdmem+0x20) & ~bitmask);
}
else if (state == SEG_OFF_BLINK_OFF)
{
// Clear segments
*lcdmem = (u8)(*lcdmem & ~bitmask);
// Clear blink segments
*(lcdmem+0x20) = (u8)(*(lcdmem+0x20) & ~bitmask);
}
}
// *************************************************************************************************
// @fn itoa
// @brief Generic integer to array routine. Converts integer n to string.
// Default conversion result has leading zeros, e.g. "00123"
// Option to convert leading '0' into whitespace (blanks)
// @param u32 n integer to convert
// u8 digits number of digits
// u8 blanks fill up result string with number of whitespaces instead of leading zeros
// @return u8 string
// *************************************************************************************************
u8 * itoa(u32 n, u8 digits, u8 blanks)
{
u8 i;
u8 digits1 = digits;
// Preset result string
memcpy(itoa_str, "0000000", 7);
// Return empty string if number of digits is invalid (valid range for digits: 1-7)
if ((digits == 0) || (digits > 7)) return (itoa_str);
// Numbers 0 .. 180 can be copied from itoa_conversion_table without conversion
if (n <= 180)
{
if (digits >= 3)
{
memcpy(itoa_str+(digits-3), itoa_conversion_table[n], 3);
}
else // digits == 1 || 2
{
memcpy(itoa_str, itoa_conversion_table[n]+(3-digits), digits);
}
}
else // For n > 180 need to calculate string content
{
// Calculate digits from least to most significant number
do
{
itoa_str[digits-1] = n % 10 + '0';
n /= 10;
} while (--digits > 0);
}
// Remove specified number of leading '0', always keep last one
i = 0;
while ((itoa_str[i] == '0') && (i < digits1-1))
{
if (blanks > 0)
{
// Convert only specified number of leading '0'
itoa_str[i]=' ';
blanks--;
}
i++;
}
return (itoa_str);
}
// *************************************************************************************************
// @fn display_value1
// @brief Generic decimal display routine. Used exclusively by set_value function.
// @param u8 segments LCD segments where value is displayed
// u32 value Integer value to be displayed
// u8 digits Number of digits to convert
// u8 blanks Number of leadings blanks in itoa result string
// @return none
// *************************************************************************************************
void display_value1(u8 segments, u32 value, u8 digits, u8 blanks)
{
u8 * str;
str = itoa(value, digits, blanks);
// Display string in blink mode
display_chars(segments, str, SEG_ON_BLINK_ON);
}
// *************************************************************************************************
// @fn display_hours
// @brief Display hours in 24H / 12H time format.
// @param u8 segments Segments where to display hour data
// u32 value Hour data
// u8 digits Must be "2"
// u8 blanks Must be "0"
// @return none
// *************************************************************************************************
void display_hours1(u8 segments, u32 value, u8 digits, u8 blanks)
{
u8 hours;
if (sys.flag.use_metric_units)
{
// Display hours in 24H time format
display_value1(segments, (u16) value, digits, blanks);
}
else
{
// convert internal 24H time format to 12H time format
hours = convert_hour_to_12H_format(value);
// display hours in 12H time format
display_value1(segments, hours, digits, blanks);
display_am_pm_symbol(value);
}
}
// *************************************************************************************************
// @fn display_am_pm_symbol
// @brief Display AM or PM symbol.
// @param u8 hour 24H internal time format
// @return none
// *************************************************************************************************
void display_am_pm_symbol(u8 hour)
{
// Display AM/PM symbol
if (is_hour_am(hour))
{
display_symbol(LCD_SYMB_AM, SEG_ON);
}
else
{
// Clear AM segments first - required when changing from AM to PM
display_symbol(LCD_SYMB_AM, SEG_OFF);
display_symbol(LCD_SYMB_PM, SEG_ON);
}
}
// *************************************************************************************************
// @fn display_symbol
// @brief Switch symbol on or off on LCD.
// @param u8 symbol A valid LCD symbol (index 0..42)
// u8 state SEG_ON, SEG_OFF, SEG_BLINK
// @return none
// *************************************************************************************************
void display_symbol(u8 symbol, u8 mode)
{
u8 * lcdmem;
u8 bits;
u8 bitmask;
if (symbol <= LCD_SEG_L2_DP)
{
// Get LCD memory address for symbol from table
lcdmem = (u8 *)segments_lcdmem[symbol];
// Get bits for symbol from table
bits = segments_bitmask[symbol];
// Bitmask for symbols equals bits
bitmask = bits;
// Write LCD memory
write_lcd_mem(lcdmem, bits, bitmask, mode);
}
}
// *************************************************************************************************
// @fn display_char
// @brief Write to 7-segment characters.
// @param u8 segment A valid LCD segment
// u8 chr Character to display
// u8 mode SEG_ON, SEG_OFF, SEG_BLINK
// @return none
// *************************************************************************************************
void display_char(u8 segment, u8 chr, u8 mode)
{
u8 * lcdmem; // Pointer to LCD memory