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)
46 mw_lcd_draw_pixel(x, y, color ? LCD_BLACK : LCD_WHITE);
49 void hal_lcd_clear_display(void)
54 void hal_lcd_update_display(void)
56 mw_lcd_update_screen();
59 void hal_lcd_set_backlight(boolean state)
68 boolean hal_lcd_get_backlight(void)
70 return (LCD_LED_POUT & LCD_LED_PIN) ? TRUE : FALSE;
73 void hal_enable_centisecond_timer(void)
75 start_timer(TIMER_100MS_CYCLES);
78 void hal_disable_centisecond_timer(void)
83 void hal_enable_halfsecond_timer(void)
85 start_timer(TIMER_500MS_CYCLES);
88 void hal_disable_halfsecond_timer(void)
93 void hal_get_rtc(clock_state *rtc)
95 /* Update clock state from RTC */
105 void hal_set_rtc(clock_state *rtc, boolean set_sec)
107 /* Update clock state from RTC */
109 RTCMIN = rtc->minute;
111 RTCSEC = rtc->second;
115 rtc->wday = getWochentag(rtc->day, rtc->month, rtc->year);
119 void hal_get_power_state(power_state *pwr)
123 pwr->source = (BAT_CHARGE_IN & BAT_CHARGE_PWR_BIT) ? POWER_SOURCE_BATTERY : POWER_SOURCE_EXTERNAL;
125 /* unless the charger is enabled we do not get a reasonable state */
126 if (!(BAT_CHARGE_IN & BAT_CHARGE_ENABLE_PIN)) {
127 switch (BAT_CHARGE_IN & (BAT_CHARGE_STAT1 | BAT_CHARGE_STAT2)) {
128 case BAT_CHARGE_STAT1:
129 pwr->charge_state = POWER_CHARGER_DONE;
131 case BAT_CHARGE_STAT2:
132 pwr->charge_state = POWER_CHARGER_CHARGING;
134 case (BAT_CHARGE_STAT1 | BAT_CHARGE_STAT2):
135 pwr->charge_state = POWER_CHARGER_UNK;
138 pwr->charge_state = POWER_CHARGER_PRECHARGE;
142 pwr->charge_state = POWER_CHARGER_UNK;
145 if ((pwr->source == POWER_SOURCE_BATTERY) && (RTCSEC != 0)) {
146 /* the ADC and activating the measuring shunts is
147 * power expensive so only do this every minute */
151 /* get new values and so some averaging to avoid jumps */
152 val = mw_get_battery_adc_val();
153 pwr->percent = mw_get_battery_percentage_from_val(val);
157 void hal_vibration_set_state(boolean state)
161 TA1CTL |= TASSEL__ACLK | MC__UPDOWN | ID_0;
170 boolean hal_vibration_get_state(void)
173 return (P7SEL & BIT3) ? TRUE : FALSE;
179 #define BLUETOOTH_DEVICE_NAME "Oswald on MetaWatch"
180 static boolean bt_is_visible = FALSE;
183 bluetooth_state hal_bluetooth_set_state(bluetooth_state state)
187 if (state == BLUETOOTH_OFF && mw_bt_is_enabled() == 1) {
189 bt_is_visible = FALSE;
190 return BLUETOOTH_OFF;
191 } else if (state == BLUETOOTH_ON && mw_bt_is_enabled() == 0) {
195 strncpy((char *)buf, BLUETOOTH_DEVICE_NAME, strlen(BLUETOOTH_DEVICE_NAME));
196 bt_hci_cmd(HCI_HC_BB_OGF, HCI_W_LOCAL_NAME_OCF, strlen(BLUETOOTH_DEVICE_NAME)+1, buf);
197 // read our local address
198 bt_hci_cmd(HCI_INFO_PARAM_OGF, HCI_R_BD_ADDR_OCF, 0, NULL);
200 buf[0] = HCI_BB_SCAN_PAGE;
201 bt_hci_cmd(HCI_HC_BB_OGF, HCI_W_SCAN_EN_OCF, 1, buf);
202 bt_is_visible = FALSE;
205 return BLUETOOTH_ILL;
208 bluetooth_state hal_bluetooth_get_state(void)
210 if (mw_bt_is_enabled() == 1) {
211 if (bt_l2cap_get_connected(0x40))
212 return BLUETOOTH_CONNECTED;
216 return BLUETOOTH_OFF;
219 uint8_t *hal_bluetooth_get_local_bdaddr(void)
221 return bt_hci_get_local_bdaddr();
224 void hal_bluetooth_set_visible(boolean visible)
228 if (mw_bt_is_enabled() == 0) {
229 bt_is_visible = FALSE;
234 // enable page and inquiry scan
235 buf[0] = HCI_BB_SCAN_INQUIRY | HCI_BB_SCAN_PAGE;
236 bt_hci_cmd(HCI_HC_BB_OGF, HCI_W_SCAN_EN_OCF, 1, buf);
237 bt_is_visible = TRUE;
239 // enable page scan only
240 buf[0] = HCI_BB_SCAN_PAGE;
241 bt_hci_cmd(HCI_HC_BB_OGF, HCI_W_SCAN_EN_OCF, 1, buf);
242 bt_is_visible = FALSE;
246 boolean hal_bluetooth_get_visible(void)
248 return bt_is_visible;
251 void hal_bluetooth_send_data(const void *mdat, uint16_t mlen)
253 bt_l2cap_send_channel(0x40, mdat, mlen);
257 * Control the accelerometer
259 void hal_accelerometer_enable(void)
264 void hal_accelerometer_disable(void)
269 uint16_t hal_amblight_get_val(void)
271 return mw_get_amblight_adc_val();