Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Maple_alarm_clock.cpp@3:eec13a411e94, 2011-10-30 (annotated)
- Committer:
- uehara00
- Date:
- Sun Oct 30 21:20:23 2011 +0000
- Revision:
- 3:eec13a411e94
- Parent:
- 2:299a1c9a5795
OLED(MARY-OB) drivers and demonstrations are added.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| uehara00 | 1:aefa1992ce0f | 1 | //copyright 2011 Uehara Yoshiyuki |
| uehara00 | 1:aefa1992ce0f | 2 | //==================================================================== |
| uehara00 | 1:aefa1992ce0f | 3 | //The author provide the programs without any guarantees or warranty. |
| uehara00 | 1:aefa1992ce0f | 4 | //The author is not responsible for any damage or losses of any kind |
| uehara00 | 1:aefa1992ce0f | 5 | //caused by using or misusing of the programs. |
| uehara00 | 1:aefa1992ce0f | 6 | //The author is under no obligation to provide support, service, |
| uehara00 | 1:aefa1992ce0f | 7 | //corrections, or upgrades to the programs. |
| uehara00 | 1:aefa1992ce0f | 8 | //==================================================================== |
| uehara00 | 0:0be38b583cf7 | 9 | // MAPLE board[MARM01-BASE] |
| uehara00 | 1:aefa1992ce0f | 10 | // alarm clock |
| uehara00 | 3:eec13a411e94 | 11 | #include "Maple_console.h" |
| uehara00 | 0:0be38b583cf7 | 12 | #include "Maple_alarm_clock.h" |
| uehara00 | 0:0be38b583cf7 | 13 | #include "Maple_RTC.h" |
| uehara00 | 0:0be38b583cf7 | 14 | #include "Maple_I2C.h" |
| uehara00 | 0:0be38b583cf7 | 15 | #include "Maple.h" |
| uehara00 | 0:0be38b583cf7 | 16 | #include "mbed.h" |
| uehara00 | 0:0be38b583cf7 | 17 | |
| uehara00 | 3:eec13a411e94 | 18 | // global variables defined in console.cpp |
| uehara00 | 3:eec13a411e94 | 19 | extern int console_mode; |
| uehara00 | 3:eec13a411e94 | 20 | extern int console_cursor; |
| uehara00 | 0:0be38b583cf7 | 21 | |
| uehara00 | 3:eec13a411e94 | 22 | // make display data of RTC clock for console |
| uehara00 | 3:eec13a411e94 | 23 | void display_clock(char row0[], char row1[], int &cursor_r, int &cursor_c) { |
| uehara00 | 3:eec13a411e94 | 24 | const int position_r[CURSOR_CLOCK_SIZE] = { 1, 1}; |
| uehara00 | 3:eec13a411e94 | 25 | const int position_c[CURSOR_CLOCK_SIZE] = { 12, 15}; |
| uehara00 | 3:eec13a411e94 | 26 | char d[17], s[4]; |
| uehara00 | 0:0be38b583cf7 | 27 | |
| uehara00 | 3:eec13a411e94 | 28 | i2c_RTC_read(RTC_REG_CONTROL1, d, 16); |
| uehara00 | 3:eec13a411e94 | 29 | copy_string(row0, 0, 17, "XXXX.XX.XX XXX "); |
| uehara00 | 3:eec13a411e94 | 30 | copy_string(row1, 0, 17, "XX:XX:XX XXXXXXX"); |
| uehara00 | 3:eec13a411e94 | 31 | if((d[RTC_REG_SECOND] & RTC_VOLTAGE_LOW) == 0) { // when RTC registers are valid: |
| uehara00 | 3:eec13a411e94 | 32 | copy_string(row0, 0, 2, "20"); |
| uehara00 | 3:eec13a411e94 | 33 | if((d[RTC_REG_MONTH_CENTURY ] & RTC_CENTURY ) != 0) { row0[ 1] = '1'; } |
| uehara00 | 3:eec13a411e94 | 34 | copy_string(row0, 2, 2, int_to_hex2(d[RTC_REG_YEAR ] , s)); |
| uehara00 | 3:eec13a411e94 | 35 | copy_string(row0, 5, 2, int_to_hex2(d[RTC_REG_MONTH_CENTURY] & 0x1f, s)); |
| uehara00 | 3:eec13a411e94 | 36 | copy_string(row0, 8, 2, int_to_hex2(d[RTC_REG_DAY ] & 0x3f, s)); |
| uehara00 | 3:eec13a411e94 | 37 | copy_string(row0, 11, 3, weekday_to_string(d[RTC_REG_WEEKDAY] & 0x07, s)); |
| uehara00 | 3:eec13a411e94 | 38 | copy_string(row1, 0, 2, int_to_hex2(d[RTC_REG_HOUR ] & 0x3f, s)); |
| uehara00 | 3:eec13a411e94 | 39 | copy_string(row1, 3, 2, int_to_hex2(d[RTC_REG_MINUTE ] & 0x7f, s)); |
| uehara00 | 3:eec13a411e94 | 40 | copy_string(row1, 6, 2, int_to_hex2(d[RTC_REG_SECOND ] & 0x7f, s)); |
| uehara00 | 3:eec13a411e94 | 41 | copy_string(row1, 9, 7, "-------"); |
| uehara00 | 3:eec13a411e94 | 42 | if((d[RTC_REG_CONTROL2 ] & RTC_TIMER_PERIODIC ) != 0) { row1[ 9] = 'p'; } |
| uehara00 | 3:eec13a411e94 | 43 | if((d[RTC_REG_TIMER_CONTROL ] & RTC_TIMER_ENABLE ) != 0) { row1[10] = 't'; } |
| uehara00 | 3:eec13a411e94 | 44 | if((d[RTC_REG_CONTROL2 ] & RTC_TIMER_INTERRUPT_ENABLE) != 0) { row1[11] = 'i'; } |
| uehara00 | 3:eec13a411e94 | 45 | if((d[RTC_REG_CONTROL2 ] & RTC_TIMER_FLAG ) != 0) { row1[12] = 'T'; } |
| uehara00 | 3:eec13a411e94 | 46 | if((d[RTC_REG_ALARM_MINUTE ] & RTC_ALARM_DISABLE ) == 0) { row1[13] = 'a'; } |
| uehara00 | 3:eec13a411e94 | 47 | if((d[RTC_REG_ALARM_HOUR ] & RTC_ALARM_DISABLE ) == 0) { row1[13] = 'a'; } |
| uehara00 | 3:eec13a411e94 | 48 | if((d[RTC_REG_ALARM_DAY ] & RTC_ALARM_DISABLE ) == 0) { row1[13] = 'a'; } |
| uehara00 | 3:eec13a411e94 | 49 | if((d[RTC_REG_ALARM_WEEKDAY ] & RTC_ALARM_DISABLE ) == 0) { row1[13] = 'a'; } |
| uehara00 | 3:eec13a411e94 | 50 | if((d[RTC_REG_CONTROL2 ] & RTC_ALARM_INTERRUPT_ENABLE) != 0) { row1[14] = 'i'; } |
| uehara00 | 3:eec13a411e94 | 51 | if((d[RTC_REG_CONTROL2 ] & RTC_ALARM_FLAG ) != 0) { row1[15] = 'A'; } |
| uehara00 | 1:aefa1992ce0f | 52 | } |
| uehara00 | 3:eec13a411e94 | 53 | cursor_r = position_r[console_cursor]; |
| uehara00 | 3:eec13a411e94 | 54 | cursor_c = position_c[console_cursor]; |
| uehara00 | 0:0be38b583cf7 | 55 | } |
| uehara00 | 0:0be38b583cf7 | 56 | |
| uehara00 | 3:eec13a411e94 | 57 | // make display data of RTC adjust for console |
| uehara00 | 3:eec13a411e94 | 58 | void display_adjust(char row0[], char row1[], int &cursor_r, int &cursor_c) { |
| uehara00 | 3:eec13a411e94 | 59 | const int position_r[CURSOR_ADJUST_SIZE] = { 0, 0, 0, 0, 1, 1, 1}; |
| uehara00 | 3:eec13a411e94 | 60 | const int position_c[CURSOR_ADJUST_SIZE] = { 1, 3, 6, 9, 1, 4, 7}; |
| uehara00 | 3:eec13a411e94 | 61 | char d[17], s[4]; |
| uehara00 | 3:eec13a411e94 | 62 | |
| uehara00 | 3:eec13a411e94 | 63 | i2c_RTC_read(RTC_REG_CONTROL1, d, 16); |
| uehara00 | 3:eec13a411e94 | 64 | copy_string(row0, 0, 17, "XXXX.XX.XX XXX "); |
| uehara00 | 3:eec13a411e94 | 65 | copy_string(row1, 0, 17, "XX:XX:XX adjust"); |
| uehara00 | 3:eec13a411e94 | 66 | if((d[RTC_REG_SECOND] & RTC_VOLTAGE_LOW) == 0) { // when RTC registers are valid: |
| uehara00 | 3:eec13a411e94 | 67 | copy_string(row0, 0, 2, "20"); |
| uehara00 | 3:eec13a411e94 | 68 | if((d[RTC_REG_MONTH_CENTURY ] & RTC_CENTURY ) != 0) { row0[ 1] = '1'; } |
| uehara00 | 3:eec13a411e94 | 69 | copy_string(row0, 2, 2, int_to_hex2(d[RTC_REG_YEAR ] , s)); |
| uehara00 | 3:eec13a411e94 | 70 | copy_string(row0, 5, 2, int_to_hex2(d[RTC_REG_MONTH_CENTURY] & 0x1f, s)); |
| uehara00 | 3:eec13a411e94 | 71 | copy_string(row0, 8, 2, int_to_hex2(d[RTC_REG_DAY ] & 0x3f, s)); |
| uehara00 | 3:eec13a411e94 | 72 | copy_string(row0, 11, 3, weekday_to_string(d[RTC_REG_WEEKDAY] & 0x07, s)); |
| uehara00 | 3:eec13a411e94 | 73 | copy_string(row1, 0, 2, int_to_hex2(d[RTC_REG_HOUR ] & 0x3f, s)); |
| uehara00 | 3:eec13a411e94 | 74 | copy_string(row1, 3, 2, int_to_hex2(d[RTC_REG_MINUTE ] & 0x7f, s)); |
| uehara00 | 3:eec13a411e94 | 75 | copy_string(row1, 6, 2, int_to_hex2(d[RTC_REG_SECOND ] & 0x7f, s)); |
| uehara00 | 3:eec13a411e94 | 76 | } |
| uehara00 | 3:eec13a411e94 | 77 | cursor_r = position_r[console_cursor]; |
| uehara00 | 3:eec13a411e94 | 78 | cursor_c = position_c[console_cursor]; |
| uehara00 | 0:0be38b583cf7 | 79 | } |
| uehara00 | 0:0be38b583cf7 | 80 | |
| uehara00 | 3:eec13a411e94 | 81 | // make display data of RTC alarm for console |
| uehara00 | 3:eec13a411e94 | 82 | void display_alarm(char row0[], char row1[], int &cursor_r, int &cursor_c) { |
| uehara00 | 3:eec13a411e94 | 83 | const int position_r[CURSOR_ALARM_SIZE] = { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}; |
| uehara00 | 3:eec13a411e94 | 84 | const int position_c[CURSOR_ALARM_SIZE] = { 4, 6, 8, 11, 14, 15, 0, 2, 4, 6}; |
| uehara00 | 3:eec13a411e94 | 85 | char d[17], s[4]; |
| uehara00 | 1:aefa1992ce0f | 86 | |
| uehara00 | 1:aefa1992ce0f | 87 | i2c_RTC_read(RTC_REG_CONTROL1, d, 16); |
| uehara00 | 3:eec13a411e94 | 88 | copy_string(row0, 0, 17, "day:XXX XXXX XXX"); |
| uehara00 | 3:eec13a411e94 | 89 | copy_string(row1, 0, 17, "XXX:XXX alarm"); |
| uehara00 | 3:eec13a411e94 | 90 | if((d[RTC_REG_SECOND] & RTC_VOLTAGE_LOW) == 0) { // when RTC registers are valid: |
| uehara00 | 3:eec13a411e94 | 91 | row0[ 4] = '-'; |
| uehara00 | 3:eec13a411e94 | 92 | row0[ 8] = '-'; |
| uehara00 | 3:eec13a411e94 | 93 | copy_string(row0, 13, 3, "---"); |
| uehara00 | 3:eec13a411e94 | 94 | row1[ 0] = '-'; |
| uehara00 | 3:eec13a411e94 | 95 | row1[ 4] = '-'; |
| uehara00 | 3:eec13a411e94 | 96 | copy_string(row0, 5, 2, int_to_hex2(d[RTC_REG_ALARM_DAY ] & 0x3f, s)); |
| uehara00 | 3:eec13a411e94 | 97 | copy_string(row0, 9, 3, weekday_to_string(d[RTC_REG_ALARM_WEEKDAY] & 0x07, s)); |
| uehara00 | 3:eec13a411e94 | 98 | copy_string(row1, 1, 2, int_to_hex2(d[RTC_REG_ALARM_HOUR ] & 0x3f, s)); |
| uehara00 | 3:eec13a411e94 | 99 | copy_string(row1, 5, 2, int_to_hex2(d[RTC_REG_ALARM_MINUTE ] & 0x7f, s)); |
| uehara00 | 3:eec13a411e94 | 100 | if((d[RTC_REG_ALARM_DAY ] & RTC_ALARM_DISABLE ) == 0) { row0[13] = 'a'; row0[ 4] = '*'; } |
| uehara00 | 3:eec13a411e94 | 101 | if((d[RTC_REG_ALARM_WEEKDAY] & RTC_ALARM_DISABLE ) == 0) { row0[13] = 'a'; row0[ 8] = '*'; } |
| uehara00 | 3:eec13a411e94 | 102 | if((d[RTC_REG_ALARM_HOUR ] & RTC_ALARM_DISABLE ) == 0) { row0[13] = 'a'; row1[ 0] = '*'; } |
| uehara00 | 3:eec13a411e94 | 103 | if((d[RTC_REG_ALARM_MINUTE ] & RTC_ALARM_DISABLE ) == 0) { row0[13] = 'a'; row1[ 4] = '*'; } |
| uehara00 | 3:eec13a411e94 | 104 | if((d[RTC_REG_CONTROL2 ] & RTC_ALARM_INTERRUPT_ENABLE) != 0) { row0[14] = 'i'; } |
| uehara00 | 3:eec13a411e94 | 105 | if((d[RTC_REG_CONTROL2 ] & RTC_ALARM_FLAG ) != 0) { row0[15] = 'A'; } |
| uehara00 | 3:eec13a411e94 | 106 | } |
| uehara00 | 3:eec13a411e94 | 107 | cursor_r = position_r[console_cursor]; |
| uehara00 | 3:eec13a411e94 | 108 | cursor_c = position_c[console_cursor]; |
| uehara00 | 3:eec13a411e94 | 109 | } |
| uehara00 | 0:0be38b583cf7 | 110 | |
| uehara00 | 3:eec13a411e94 | 111 | // make display data of RTC timer for console |
| uehara00 | 3:eec13a411e94 | 112 | void display_timer(char row0[], char row1[], int &cursor_r, int &cursor_c) { |
| uehara00 | 3:eec13a411e94 | 113 | const int position_r[CURSOR_TIMER_SIZE] = { 0, 0, 0, 0, 0, 0, 0, 1}; |
| uehara00 | 3:eec13a411e94 | 114 | const int position_c[CURSOR_TIMER_SIZE] = { 3, 8, 11, 12, 13, 14, 15, 6}; |
| uehara00 | 3:eec13a411e94 | 115 | const char select_f[4][6] = { "32768", " 1024", " 32", " 1" }; |
| uehara00 | 3:eec13a411e94 | 116 | const char select_t[4][5] = { "4096", " 64", " 1", "1/60" }; |
| uehara00 | 3:eec13a411e94 | 117 | char d[17], s[3]; |
| uehara00 | 0:0be38b583cf7 | 118 | |
| uehara00 | 3:eec13a411e94 | 119 | i2c_RTC_read(RTC_REG_CONTROL1, d, 16); |
| uehara00 | 3:eec13a411e94 | 120 | copy_string(row0, 0, 17, "XXXXHz XX XXXXX"); |
| uehara00 | 3:eec13a411e94 | 121 | copy_string(row1, 0, 17, "f=XXXXXHz timer"); |
| uehara00 | 3:eec13a411e94 | 122 | if((d[RTC_REG_SECOND] & RTC_VOLTAGE_LOW) == 0) { // when RTC registers are valid: |
| uehara00 | 3:eec13a411e94 | 123 | copy_string(row0, 0, 4, select_t[d[RTC_REG_TIMER_CONTROL] & 0x03]); |
| uehara00 | 3:eec13a411e94 | 124 | copy_string(row0, 7, 2, int_to_hex2(d[RTC_REG_TIMER], s)); |
| uehara00 | 3:eec13a411e94 | 125 | copy_string(row1, 2, 5, select_f[d[RTC_REG_CLKOUT_FREQUENCY] & 0x03]); |
| uehara00 | 3:eec13a411e94 | 126 | copy_string(row0, 11, 5, "-----"); |
| uehara00 | 3:eec13a411e94 | 127 | if((d[RTC_REG_CLKOUT_FREQUENCY] & RTC_CLKOUT_ENABLE ) != 0) { row0[11] = 'f'; } |
| uehara00 | 3:eec13a411e94 | 128 | if((d[RTC_REG_CONTROL2 ] & RTC_TIMER_PERIODIC ) != 0) { row0[12] = 'p'; } |
| uehara00 | 3:eec13a411e94 | 129 | if((d[RTC_REG_TIMER_CONTROL ] & RTC_TIMER_ENABLE ) != 0) { row0[13] = 't'; } |
| uehara00 | 3:eec13a411e94 | 130 | if((d[RTC_REG_CONTROL2 ] & RTC_TIMER_INTERRUPT_ENABLE) != 0) { row0[14] = 'i'; } |
| uehara00 | 3:eec13a411e94 | 131 | if((d[RTC_REG_CONTROL2 ] & RTC_TIMER_FLAG ) != 0) { row0[15] = 'T'; } |
| uehara00 | 3:eec13a411e94 | 132 | } |
| uehara00 | 3:eec13a411e94 | 133 | cursor_r = position_r[console_cursor]; |
| uehara00 | 3:eec13a411e94 | 134 | cursor_c = position_c[console_cursor]; |
| uehara00 | 1:aefa1992ce0f | 135 | } |
| uehara00 | 1:aefa1992ce0f | 136 | |
| uehara00 | 3:eec13a411e94 | 137 | // enter mode clock |
| uehara00 | 3:eec13a411e94 | 138 | void enter_mode_clock() { |
| uehara00 | 3:eec13a411e94 | 139 | console_mode = MODE_CLOCK; |
| uehara00 | 3:eec13a411e94 | 140 | console_cursor = CURSOR_CLOCK_INIT; |
| uehara00 | 1:aefa1992ce0f | 141 | } |
| uehara00 | 1:aefa1992ce0f | 142 | |
| uehara00 | 3:eec13a411e94 | 143 | // enter mode adjust |
| uehara00 | 3:eec13a411e94 | 144 | void enter_mode_adjust() { |
| uehara00 | 3:eec13a411e94 | 145 | console_mode = MODE_ADJUST; |
| uehara00 | 3:eec13a411e94 | 146 | console_cursor = CURSOR_ADJUST_INIT; |
| uehara00 | 0:0be38b583cf7 | 147 | } |
| uehara00 | 0:0be38b583cf7 | 148 | |
| uehara00 | 3:eec13a411e94 | 149 | // enter mode alarm |
| uehara00 | 3:eec13a411e94 | 150 | void enter_mode_alarm() { |
| uehara00 | 3:eec13a411e94 | 151 | console_mode = MODE_ALARM; |
| uehara00 | 3:eec13a411e94 | 152 | console_cursor = CURSOR_ALARM_INIT; |
| uehara00 | 0:0be38b583cf7 | 153 | } |
| uehara00 | 0:0be38b583cf7 | 154 | |
| uehara00 | 3:eec13a411e94 | 155 | // enter mode timer |
| uehara00 | 3:eec13a411e94 | 156 | void enter_mode_timer() { |
| uehara00 | 3:eec13a411e94 | 157 | console_mode = MODE_TIMER; |
| uehara00 | 3:eec13a411e94 | 158 | console_cursor = CURSOR_TIMER_INIT; |
| uehara00 | 0:0be38b583cf7 | 159 | } |
| uehara00 | 0:0be38b583cf7 | 160 | |
| uehara00 | 3:eec13a411e94 | 161 | // move cursor of clock |
| uehara00 | 3:eec13a411e94 | 162 | // flag 0:left, 1:right |
| uehara00 | 3:eec13a411e94 | 163 | void cursor_move_clock(int flag) { |
| uehara00 | 3:eec13a411e94 | 164 | cursor_move(flag, CURSOR_CLOCK_SIZE); |
| uehara00 | 3:eec13a411e94 | 165 | } |
| uehara00 | 3:eec13a411e94 | 166 | |
| uehara00 | 3:eec13a411e94 | 167 | // move cursor of adjust |
| uehara00 | 3:eec13a411e94 | 168 | // flag 0:left, 1:right |
| uehara00 | 3:eec13a411e94 | 169 | void cursor_move_adjust(int flag) { |
| uehara00 | 3:eec13a411e94 | 170 | cursor_move(flag, CURSOR_ADJUST_SIZE); |
| uehara00 | 0:0be38b583cf7 | 171 | } |
| uehara00 | 0:0be38b583cf7 | 172 | |
| uehara00 | 3:eec13a411e94 | 173 | // move cursor of alarm |
| uehara00 | 1:aefa1992ce0f | 174 | // flag 0:left, 1:right |
| uehara00 | 3:eec13a411e94 | 175 | void cursor_move_alarm(int flag) { |
| uehara00 | 3:eec13a411e94 | 176 | cursor_move(flag, CURSOR_ALARM_SIZE); |
| uehara00 | 1:aefa1992ce0f | 177 | } |
| uehara00 | 0:0be38b583cf7 | 178 | |
| uehara00 | 3:eec13a411e94 | 179 | // move cursor of timer |
| uehara00 | 3:eec13a411e94 | 180 | // flag 0:left, 1:right |
| uehara00 | 3:eec13a411e94 | 181 | void cursor_move_timer(int flag) { |
| uehara00 | 3:eec13a411e94 | 182 | cursor_move(flag, CURSOR_TIMER_SIZE); |
| uehara00 | 1:aefa1992ce0f | 183 | } |
| uehara00 | 0:0be38b583cf7 | 184 | |
| uehara00 | 3:eec13a411e94 | 185 | // increment/decrement of clock |
| uehara00 | 1:aefa1992ce0f | 186 | // flag 0:decrement, 1:increment |
| uehara00 | 3:eec13a411e94 | 187 | void button_xxcrement_clock(int flag) { |
| uehara00 | 1:aefa1992ce0f | 188 | char d; |
| uehara00 | 0:0be38b583cf7 | 189 | |
| uehara00 | 1:aefa1992ce0f | 190 | d = RTC_read1(RTC_REG_CONTROL2); |
| uehara00 | 3:eec13a411e94 | 191 | switch(console_cursor) { |
| uehara00 | 3:eec13a411e94 | 192 | case CURSOR_CLOCK_TIMER_FLAG: |
| uehara00 | 1:aefa1992ce0f | 193 | d = d & 0x1b | (flag == 0 ? 0x00 : 0x04); |
| uehara00 | 1:aefa1992ce0f | 194 | break; |
| uehara00 | 3:eec13a411e94 | 195 | case CURSOR_CLOCK_ALARM_FLAG: |
| uehara00 | 1:aefa1992ce0f | 196 | d = d & 0x17 | (flag == 0 ? 0x00 : 0x08); |
| uehara00 | 1:aefa1992ce0f | 197 | break; |
| uehara00 | 1:aefa1992ce0f | 198 | } |
| uehara00 | 1:aefa1992ce0f | 199 | RTC_write1(RTC_REG_CONTROL2, d); |
| uehara00 | 1:aefa1992ce0f | 200 | } |
| uehara00 | 1:aefa1992ce0f | 201 | |
| uehara00 | 3:eec13a411e94 | 202 | // increment/decrement of adjust |
| uehara00 | 1:aefa1992ce0f | 203 | // flag 0:decrement, 1:increment |
| uehara00 | 3:eec13a411e94 | 204 | void button_xxcrement_adjust(int flag) { |
| uehara00 | 1:aefa1992ce0f | 205 | char d; |
| uehara00 | 0:0be38b583cf7 | 206 | |
| uehara00 | 3:eec13a411e94 | 207 | switch(console_cursor) { |
| uehara00 | 1:aefa1992ce0f | 208 | case CURSOR_ADJUST_HOUR: |
| uehara00 | 1:aefa1992ce0f | 209 | d = RTC_stop_read1(RTC_REG_HOUR) & 0x3F; |
| uehara00 | 1:aefa1992ce0f | 210 | d = xxcrement_bcd(flag, d, 0x00, 0x23); |
| uehara00 | 1:aefa1992ce0f | 211 | RTC_write1_start(RTC_REG_HOUR, d); |
| uehara00 | 1:aefa1992ce0f | 212 | break; |
| uehara00 | 1:aefa1992ce0f | 213 | case CURSOR_ADJUST_MINUTE: |
| uehara00 | 1:aefa1992ce0f | 214 | d = RTC_stop_read1(RTC_REG_MINUTE) & 0x7F; |
| uehara00 | 1:aefa1992ce0f | 215 | d = xxcrement_bcd(flag, d, 0x00, 0x59); |
| uehara00 | 1:aefa1992ce0f | 216 | RTC_write1_start(RTC_REG_MINUTE, d); |
| uehara00 | 1:aefa1992ce0f | 217 | break; |
| uehara00 | 1:aefa1992ce0f | 218 | case CURSOR_ADJUST_SECOND: |
| uehara00 | 1:aefa1992ce0f | 219 | d = RTC_stop_read1(RTC_REG_SECOND) & 0x7f; |
| uehara00 | 1:aefa1992ce0f | 220 | d = (flag == 0 ? 0x30 : 0x00); |
| uehara00 | 1:aefa1992ce0f | 221 | RTC_write1_start(RTC_REG_SECOND, d); |
| uehara00 | 1:aefa1992ce0f | 222 | break; |
| uehara00 | 1:aefa1992ce0f | 223 | default: |
| uehara00 | 1:aefa1992ce0f | 224 | button_xxcrement_adjust_date(flag); |
| uehara00 | 0:0be38b583cf7 | 225 | } |
| uehara00 | 0:0be38b583cf7 | 226 | } |
| uehara00 | 0:0be38b583cf7 | 227 | |
| uehara00 | 1:aefa1992ce0f | 228 | // increment/decrement century, year, month, day |
| uehara00 | 1:aefa1992ce0f | 229 | // flag 0:decrement, 1:increment |
| uehara00 | 1:aefa1992ce0f | 230 | static void button_xxcrement_adjust_date(int flag) { |
| uehara00 | 1:aefa1992ce0f | 231 | char century, bcd_year, bcd_month, bcd_day, weekday, d; |
| uehara00 | 1:aefa1992ce0f | 232 | |
| uehara00 | 1:aefa1992ce0f | 233 | RTC_stop_read_date(century, bcd_year, bcd_month, bcd_day); |
| uehara00 | 3:eec13a411e94 | 234 | switch(console_cursor) { |
| uehara00 | 1:aefa1992ce0f | 235 | case CURSOR_ADJUST_CENTURY: |
| uehara00 | 1:aefa1992ce0f | 236 | century = xxcrement_bcd(flag, century, 0x00, 0x01); |
| uehara00 | 1:aefa1992ce0f | 237 | break; |
| uehara00 | 1:aefa1992ce0f | 238 | case CURSOR_ADJUST_YEAR: |
| uehara00 | 1:aefa1992ce0f | 239 | bcd_year = xxcrement_bcd(flag, bcd_year, 0x00, 0x99); |
| uehara00 | 1:aefa1992ce0f | 240 | break; |
| uehara00 | 1:aefa1992ce0f | 241 | case CURSOR_ADJUST_MONTH: |
| uehara00 | 1:aefa1992ce0f | 242 | bcd_month = xxcrement_bcd(flag, bcd_month, 0x01, 0x12); |
| uehara00 | 1:aefa1992ce0f | 243 | break; |
| uehara00 | 1:aefa1992ce0f | 244 | case CURSOR_ADJUST_DAY: |
| uehara00 | 1:aefa1992ce0f | 245 | bcd_day = xxcrement_bcd(flag, bcd_day, 0x01, bcd_days_in_month(century, bcd_year, bcd_month)); |
| uehara00 | 1:aefa1992ce0f | 246 | break; |
| uehara00 | 1:aefa1992ce0f | 247 | } |
| uehara00 | 1:aefa1992ce0f | 248 | d = bcd_days_in_month(century, bcd_year, bcd_month); |
| uehara00 | 1:aefa1992ce0f | 249 | if(bcd_day > d) { |
| uehara00 | 1:aefa1992ce0f | 250 | bcd_day = d; |
| uehara00 | 1:aefa1992ce0f | 251 | } |
| uehara00 | 1:aefa1992ce0f | 252 | weekday = bcd_date_to_weekday(century, bcd_year, bcd_month, bcd_day); |
| uehara00 | 1:aefa1992ce0f | 253 | RTC_write_date_start(century, bcd_year, bcd_month, bcd_day, weekday); |
| uehara00 | 1:aefa1992ce0f | 254 | } |
| uehara00 | 1:aefa1992ce0f | 255 | |
| uehara00 | 3:eec13a411e94 | 256 | // increment/decrement of alarm |
| uehara00 | 1:aefa1992ce0f | 257 | // flag 0:decrement, 1:increment |
| uehara00 | 3:eec13a411e94 | 258 | void button_xxcrement_alarm(int flag) { |
| uehara00 | 1:aefa1992ce0f | 259 | char d; |
| uehara00 | 1:aefa1992ce0f | 260 | |
| uehara00 | 3:eec13a411e94 | 261 | switch(console_cursor) { |
| uehara00 | 1:aefa1992ce0f | 262 | case CURSOR_ALARM_DAY_DISABLE: |
| uehara00 | 1:aefa1992ce0f | 263 | d = RTC_read1(RTC_REG_ALARM_DAY) & 0x3f | (flag == 0 ? 0x80 : 0x00); |
| uehara00 | 1:aefa1992ce0f | 264 | RTC_write1(RTC_REG_ALARM_DAY, d); |
| uehara00 | 1:aefa1992ce0f | 265 | break; |
| uehara00 | 1:aefa1992ce0f | 266 | case CURSOR_ALARM_DAY: |
| uehara00 | 1:aefa1992ce0f | 267 | d = RTC_read1(RTC_REG_ALARM_DAY); |
| uehara00 | 1:aefa1992ce0f | 268 | d = xxcrement_bcd(flag, d & 0x3f, 0x00, 0x31) | d & 0x80; |
| uehara00 | 1:aefa1992ce0f | 269 | RTC_write1(RTC_REG_ALARM_DAY, d); |
| uehara00 | 1:aefa1992ce0f | 270 | break; |
| uehara00 | 1:aefa1992ce0f | 271 | case CURSOR_ALARM_WEEKDAY_DISABLE: |
| uehara00 | 1:aefa1992ce0f | 272 | d = RTC_read1(RTC_REG_ALARM_WEEKDAY) & 0x07 | (flag == 0 ? 0x80 : 0x00); |
| uehara00 | 1:aefa1992ce0f | 273 | RTC_write1(RTC_REG_ALARM_WEEKDAY, d); |
| uehara00 | 1:aefa1992ce0f | 274 | break; |
| uehara00 | 1:aefa1992ce0f | 275 | case CURSOR_ALARM_WEEKDAY: |
| uehara00 | 1:aefa1992ce0f | 276 | d = RTC_read1(RTC_REG_ALARM_WEEKDAY); |
| uehara00 | 1:aefa1992ce0f | 277 | d = xxcrement_bcd(flag, d & 0x07, 0x00, 0x06) | d & 0x80; |
| uehara00 | 1:aefa1992ce0f | 278 | RTC_write1(RTC_REG_ALARM_WEEKDAY, d); |
| uehara00 | 1:aefa1992ce0f | 279 | break; |
| uehara00 | 1:aefa1992ce0f | 280 | case CURSOR_ALARM_INTERRUPT: |
| uehara00 | 1:aefa1992ce0f | 281 | d = RTC_read1(RTC_REG_CONTROL2) & 0x1d | (flag == 0 ? 0x00 : 0x02); |
| uehara00 | 1:aefa1992ce0f | 282 | RTC_write1(RTC_REG_CONTROL2, d); |
| uehara00 | 1:aefa1992ce0f | 283 | break; |
| uehara00 | 1:aefa1992ce0f | 284 | case CURSOR_ALARM_FLAG: |
| uehara00 | 1:aefa1992ce0f | 285 | d = RTC_read1(RTC_REG_CONTROL2) & 0x17 | (flag == 0 ? 0x00 : 0x08); |
| uehara00 | 1:aefa1992ce0f | 286 | RTC_write1(RTC_REG_CONTROL2, d); |
| uehara00 | 1:aefa1992ce0f | 287 | break; |
| uehara00 | 1:aefa1992ce0f | 288 | case CURSOR_ALARM_HOUR_DISABLE: |
| uehara00 | 1:aefa1992ce0f | 289 | d = RTC_read1(RTC_REG_ALARM_HOUR) & 0x3f | (flag == 0 ? 0x80 : 0x00); |
| uehara00 | 1:aefa1992ce0f | 290 | RTC_write1(RTC_REG_ALARM_HOUR, d); |
| uehara00 | 1:aefa1992ce0f | 291 | break; |
| uehara00 | 1:aefa1992ce0f | 292 | case CURSOR_ALARM_HOUR: |
| uehara00 | 1:aefa1992ce0f | 293 | d = RTC_read1(RTC_REG_ALARM_HOUR); |
| uehara00 | 1:aefa1992ce0f | 294 | d = xxcrement_bcd(flag, d & 0x3f, 0x00, 0x23) | d & 0x80; |
| uehara00 | 1:aefa1992ce0f | 295 | RTC_write1(RTC_REG_ALARM_HOUR, d); |
| uehara00 | 1:aefa1992ce0f | 296 | break; |
| uehara00 | 1:aefa1992ce0f | 297 | case CURSOR_ALARM_MINUTE_DISABLE: |
| uehara00 | 1:aefa1992ce0f | 298 | d = RTC_read1(RTC_REG_ALARM_MINUTE) & 0x7f | (flag == 0 ? 0x80 : 0x00); |
| uehara00 | 1:aefa1992ce0f | 299 | RTC_write1(RTC_REG_ALARM_MINUTE, d); |
| uehara00 | 1:aefa1992ce0f | 300 | break; |
| uehara00 | 1:aefa1992ce0f | 301 | case CURSOR_ALARM_MINUTE: |
| uehara00 | 1:aefa1992ce0f | 302 | d = RTC_read1(RTC_REG_ALARM_MINUTE); |
| uehara00 | 1:aefa1992ce0f | 303 | d = xxcrement_bcd(flag, d & 0x7f, 0x00, 0x59) | d & 0x80; |
| uehara00 | 1:aefa1992ce0f | 304 | RTC_write1(RTC_REG_ALARM_MINUTE, d); |
| uehara00 | 1:aefa1992ce0f | 305 | break; |
| uehara00 | 0:0be38b583cf7 | 306 | } |
| uehara00 | 0:0be38b583cf7 | 307 | } |
| uehara00 | 0:0be38b583cf7 | 308 | |
| uehara00 | 3:eec13a411e94 | 309 | // increment/decrement of timer |
| uehara00 | 1:aefa1992ce0f | 310 | // flag 0:decrement, 1:increment |
| uehara00 | 3:eec13a411e94 | 311 | void button_xxcrement_timer(int flag) { |
| uehara00 | 1:aefa1992ce0f | 312 | char d; |
| uehara00 | 0:0be38b583cf7 | 313 | |
| uehara00 | 3:eec13a411e94 | 314 | switch(console_cursor) { |
| uehara00 | 1:aefa1992ce0f | 315 | case CURSOR_TIMER_SELECT: |
| uehara00 | 1:aefa1992ce0f | 316 | d = RTC_read1(RTC_REG_TIMER_CONTROL); |
| uehara00 | 1:aefa1992ce0f | 317 | d = xxcrement_bcd(flag, d & 0x03, 0x00, 0x03) | d & 0x80; |
| uehara00 | 1:aefa1992ce0f | 318 | RTC_write1(RTC_REG_TIMER_CONTROL, d); |
| uehara00 | 1:aefa1992ce0f | 319 | break; |
| uehara00 | 1:aefa1992ce0f | 320 | case CURSOR_TIMER_COUNT: |
| uehara00 | 1:aefa1992ce0f | 321 | d = RTC_read1(RTC_REG_TIMER); |
| uehara00 | 1:aefa1992ce0f | 322 | switch(flag) { |
| uehara00 | 3:eec13a411e94 | 323 | case 0: --d; break; |
| uehara00 | 3:eec13a411e94 | 324 | default: ++d; |
| uehara00 | 0:0be38b583cf7 | 325 | } |
| uehara00 | 1:aefa1992ce0f | 326 | RTC_write1(RTC_REG_TIMER, d); |
| uehara00 | 1:aefa1992ce0f | 327 | break; |
| uehara00 | 1:aefa1992ce0f | 328 | case CURSOR_CLKOUT_ENABLE: |
| uehara00 | 1:aefa1992ce0f | 329 | d = RTC_read1(RTC_REG_CLKOUT_FREQUENCY) & 0x03 | (flag == 0 ? 0x00 : 0x80); |
| uehara00 | 1:aefa1992ce0f | 330 | RTC_write1(RTC_REG_CLKOUT_FREQUENCY, d); |
| uehara00 | 1:aefa1992ce0f | 331 | break; |
| uehara00 | 1:aefa1992ce0f | 332 | case CURSOR_TIMER_PERIODIC: |
| uehara00 | 1:aefa1992ce0f | 333 | d = RTC_read1(RTC_REG_CONTROL2) & 0x0f | (flag == 0 ? 0x00 : 0x10); |
| uehara00 | 1:aefa1992ce0f | 334 | RTC_write1(RTC_REG_CONTROL2, d); |
| uehara00 | 1:aefa1992ce0f | 335 | break; |
| uehara00 | 1:aefa1992ce0f | 336 | case CURSOR_TIMER_ENABLE: |
| uehara00 | 1:aefa1992ce0f | 337 | d = RTC_read1(RTC_REG_TIMER_CONTROL) & 0x03 | (flag == 0 ? 0x00 : 0x80); |
| uehara00 | 1:aefa1992ce0f | 338 | RTC_write1(RTC_REG_TIMER_CONTROL, d); |
| uehara00 | 1:aefa1992ce0f | 339 | break; |
| uehara00 | 1:aefa1992ce0f | 340 | case CURSOR_TIMER_INTERRUPT: |
| uehara00 | 1:aefa1992ce0f | 341 | d = RTC_read1(RTC_REG_CONTROL2) & 0x1e | (flag == 0 ? 0x00 : 0x01); |
| uehara00 | 1:aefa1992ce0f | 342 | RTC_write1(RTC_REG_CONTROL2, d); |
| uehara00 | 1:aefa1992ce0f | 343 | break; |
| uehara00 | 1:aefa1992ce0f | 344 | case CURSOR_TIMER_FLAG: |
| uehara00 | 1:aefa1992ce0f | 345 | d = RTC_read1(RTC_REG_CONTROL2) & 0x1b | (flag == 0 ? 0x00 : 0x04); |
| uehara00 | 1:aefa1992ce0f | 346 | RTC_write1(RTC_REG_CONTROL2, d); |
| uehara00 | 1:aefa1992ce0f | 347 | break; |
| uehara00 | 1:aefa1992ce0f | 348 | case CURSOR_CLKOUT_FREQUENCY: |
| uehara00 | 1:aefa1992ce0f | 349 | d = RTC_read1(RTC_REG_CLKOUT_FREQUENCY); |
| uehara00 | 1:aefa1992ce0f | 350 | d = xxcrement_bcd(flag, d & 0x03, 0x00, 0x03) | d & 0x80; |
| uehara00 | 1:aefa1992ce0f | 351 | RTC_write1(RTC_REG_CLKOUT_FREQUENCY, d); |
| uehara00 | 1:aefa1992ce0f | 352 | break; |
| uehara00 | 0:0be38b583cf7 | 353 | } |
| uehara00 | 0:0be38b583cf7 | 354 | } |