5 #include <msp430xgeneric.h>
16 #include "bluetooth_init_cc256x.h"
20 #include "oswald_hal.h"
25 const char *hal_get_version_string(void)
27 return MW_MAIN_VERSION;
30 const char *hal_get_buildno_string(void)
35 const char *hal_get_radio_version_string(void)
37 return cc256x_version;
40 void hal_lcd_set_pixel(uint8_t x, uint8_t y, uint8_t color)
44 mw_lcd_draw_pixel(x, y, color ? LCD_BLACK : LCD_WHITE);
47 void hal_lcd_clear_display(void)
52 void hal_lcd_update_display(void)
54 mw_lcd_update_screen();
57 void hal_lcd_set_backlight(boolean state)
66 boolean hal_lcd_get_backlight(void)
68 return (LCD_LED_POUT & LCD_LED_PIN) ? TRUE : FALSE;
71 void hal_enable_centisecond_timer(void)
73 start_timer(TIMER_100MS_CYCLES);
76 void hal_disable_centisecond_timer(void)
81 void hal_enable_halfsecond_timer(void)
83 start_timer(TIMER_500MS_CYCLES);
86 void hal_disable_halfsecond_timer(void)
91 void hal_get_rtc(clock_state *rtc)
93 /* Update clock state from RTC */
102 void hal_set_rtc(clock_state *rtc, boolean set_sec)
104 /* Update clock state from RTC */
106 RTCMIN = rtc->minute;
108 RTCSEC = rtc->second;
112 rtc->wday = getWochentag(rtc->day, rtc->month, rtc->year);
116 void hal_get_power_state(power_state *pwr)
120 pwr->source = (BAT_CHARGE_IN & BAT_CHARGE_PWR_BIT) ? POWER_SOURCE_BATTERY : POWER_SOURCE_EXTERNAL;
122 /* unless the charger is enabled we do not get a reasonable state */
123 if (!(BAT_CHARGE_IN & BAT_CHARGE_ENABLE_PIN)) {
124 switch (BAT_CHARGE_IN & (BAT_CHARGE_STAT1 | BAT_CHARGE_STAT2)) {
125 case BAT_CHARGE_STAT1:
126 pwr->charge_state = POWER_CHARGER_DONE;
128 case BAT_CHARGE_STAT2:
129 pwr->charge_state = POWER_CHARGER_CHARGING;
131 case (BAT_CHARGE_STAT1 | BAT_CHARGE_STAT2):
132 pwr->charge_state = POWER_CHARGER_UNK;
135 pwr->charge_state = POWER_CHARGER_PRECHARGE;
139 pwr->charge_state = POWER_CHARGER_UNK;
142 if ((pwr->source == POWER_SOURCE_BATTERY) && (RTCSEC != 0)) {
143 /* the ADC and activating the measuring shunts is
144 * power expensive so only do this every minute */
148 /* get new values and so some averaging to avoid jumps */
149 val = mw_get_battery_adc_val();
150 pwr->percent = mw_get_battery_percentage_from_val(val);
154 void hal_vibration_set_state(boolean state)
158 TA1CTL |= TASSEL__ACLK | MC__UPDOWN | ID_0;
167 boolean hal_vibration_get_state(void)
170 return (P7SEL & BIT3) ? TRUE : FALSE;
176 #define BLUETOOTH_DEVICE_NAME "Oswald on MetaWatch"
177 static boolean bt_is_visible = FALSE;
180 bluetooth_state hal_bluetooth_set_state(bluetooth_state state)
184 if (state == BLUETOOTH_OFF && mw_bt_is_enabled() == 1) {
186 bt_is_visible = FALSE;
187 return BLUETOOTH_OFF;
188 } else if (state == BLUETOOTH_ON && mw_bt_is_enabled() == 0) {
192 strncpy((char *)buf, BLUETOOTH_DEVICE_NAME, strlen(BLUETOOTH_DEVICE_NAME));
193 bt_hci_cmd(HCI_HC_BB_OGF, HCI_W_LOCAL_NAME_OCF, strlen(BLUETOOTH_DEVICE_NAME)+1, buf);
194 // read our local address
195 bt_hci_cmd(HCI_INFO_PARAM_OGF, HCI_R_BD_ADDR_OCF, 0, NULL);
197 buf[0] = HCI_BB_SCAN_PAGE;
198 bt_hci_cmd(HCI_HC_BB_OGF, HCI_W_SCAN_EN_OCF, 1, buf);
199 bt_is_visible = FALSE;
202 return BLUETOOTH_ILL;
205 bluetooth_state hal_bluetooth_get_state(void)
207 if (mw_bt_is_enabled() == 1) {
208 if (bt_l2cap_get_connected(0x40))
209 return BLUETOOTH_CONNECTED;
213 return BLUETOOTH_OFF;
216 uint8_t *hal_bluetooth_get_local_bdaddr(void)
218 return bt_hci_get_local_bdaddr();
221 void hal_bluetooth_set_visible(boolean visible)
225 if (mw_bt_is_enabled() == 0) {
226 bt_is_visible = FALSE;
231 // enable page and inquiry scan
232 buf[0] = HCI_BB_SCAN_INQUIRY | HCI_BB_SCAN_PAGE;
233 bt_hci_cmd(HCI_HC_BB_OGF, HCI_W_SCAN_EN_OCF, 1, buf);
234 bt_is_visible = TRUE;
236 // enable page scan only
237 buf[0] = HCI_BB_SCAN_PAGE;
238 bt_hci_cmd(HCI_HC_BB_OGF, HCI_W_SCAN_EN_OCF, 1, buf);
239 bt_is_visible = FALSE;
243 boolean hal_bluetooth_get_visible(void)
245 return bt_is_visible;
248 void hal_bluetooth_send_data(const void *mdat, uint16_t mlen)
250 bt_l2cap_send_channel(0x40, mdat, mlen);
254 * Control the accelerometer
256 void hal_accelerometer_enable(void)
261 void hal_accelerometer_disable(void)