mw_bt_uart_tx(data, data_len);
}
+typedef struct {
+ uint16_t acl_handle;
+ uint16_t max_interval;
+ uint16_t min_interval;
+ uint16_t sniff_attempt;
+ uint16_t sniff_timeout;
+} __attribute__((packed)) bt_hci_sniff_cmd_t;
+
+void bt_hci_set_sniff_mode(const uint16_t acl_handle, const uint16_t max_interval, const uint16_t min_interval, const uint16_t sniff_attempt, const uint16_t sniff_timeout)
+{
+ bt_hci_sniff_cmd_t sniff_cmd;
+
+ sniff_cmd.acl_handle = acl_handle;
+ sniff_cmd.max_interval = max_interval;
+ sniff_cmd.min_interval = min_interval;
+ sniff_cmd.sniff_attempt = sniff_attempt;
+ sniff_cmd.sniff_timeout = sniff_timeout;
+
+ bt_hci_cmd(HCI_LINK_POLICY_OGF, HCI_SNIFF_MODE_OCF, sizeof(sniff_cmd), &sniff_cmd);
+}
+
typedef struct {
uint8_t type;
uint16_t handle;
#define HCI_R_STORED_LINK_KEY_OCF 0x0D
#define HCI_W_STORED_LINK_KEY_OCF 0x11
#define HCI_LINK_KEY_REQ_REP_OCF 0x0B
+#define HCI_SNIFF_MODE_OCF 0x03
#define HCI_COMMAND_PACKET 0x01
#define HCI_ACL_DATA_PACKET 0x02
void bt_hci_init(void);
void bt_hci_cmd(const uint8_t OGF, const uint8_t OCF, const uint8_t data_len, const void *data);
+void bt_hci_set_sniff_mode(const uint16_t acl_handle, const uint16_t max_interval, const uint16_t min_interval, const uint16_t sniff_attempt, const uint16_t sniff_timeout);
void bt_acl_send(const uint16_t handle, const uint8_t PB, const uint8_t BC, const uint16_t channel, const uint16_t len, const void *dat);
uint8_t *bt_hci_get_local_bdaddr(void);
void bt_hci_ehcill_wake(void);
#endif
-
{
bt_l2cap_conn_resp_t resp;
- if (_l2cap_con.cstate == BT_L2CAP_CON_IDLE) {
+ // for now we only support one connection, only on PSM 0x1001
+ if (_l2cap_con.cstate == BT_L2CAP_CON_IDLE && PSM == 0x1001) {
bt_l2cap_conf_req_t req;
_l2cap_con.cstate = BT_L2CAP_CON_CONNECTED;
req.odat = _l2cap_con.locMTU;
bt_acl_send(handle, PB_FIRST_FLUSHABLE, BC_NO_BROADCAST, L2CAP_CID_SIGNALING, sizeof(bt_l2cap_conf_req_t), &req);
+
+ // max_interval Mandatory Range: 0x0006 to 0x0540
+ // min_interval Mandatory Range: 0x0006 to 0x0540
+ // sniff_attempt Mandatory Range for Controller: 1 to Tsniff/2
+ // sniff_timeout Mandatory Range for Controller: 0 to 0x0028
+ bt_hci_set_sniff_mode(handle, 0x10, 0x06, 0x20, 0x10);
} else {
resp.resp = CONNECTION_RESPONSE;
resp.ident = ident;
/* this causes data to always be sent */
// WriteRegisterData = 0x00;
- WriteRegisterData = 0x02 /*0x08*/;
+ WriteRegisterData = 0x01 /*0x08*/;
mw_acc_i2c_write(KIONIX_WUF_THRESH, &WriteRegisterData, 1);
/* single byte read test */
ENABLE_ADC();
/* WaitForAdcBusy(); */
- while (ADC12CTL1 & ADC12BUSY);
+ while (ADC12CTL1 & ADC12BUSY)
+ nop();
- /* Convert the ADC count for the battery input into a voltage
+ /* Convert the ADC count for the battery input into a voltage
* ADC12MEM1: Counts Battery Voltage in ADC counts
* Result: Battery voltage in millivolts */
BATTERY_SENSE_DISABLE();
- return (unsigned int)(CONVERSION_FACTOR_BATTERY * (double)ADC12MEM1);
+ return (unsigned int)(CONVERSION_FACTOR_BATTERY * (double)ADC12MEM1);
}
-unsigned char mw_get_battery_percentage_from_val(unsigned int BattVal)
+uint8_t mw_get_battery_percentage_from_val(unsigned int BattVal)
{
if (BattVal > BATTERY_FULL_LEVEL)
BattVal = BATTERY_FULL_LEVEL;
return (unsigned char)BattVal;
}
+unsigned int mw_get_amblight_adc_val(void)
+{
+ LIGHT_SENSE_ENABLE();
+
+ CLEAR_START_ADDR();
+ ADC12CTL1 |= ADC12CSTARTADD_2;
+ ENABLE_ADC();
+
+ /* WaitForAdcBusy(); */
+ while (ADC12CTL1 & ADC12BUSY)
+ nop();
+
+ LIGHT_SENSE_DISABLE();
+
+ return ADC12MEM2;
+}
+
void mw_init_adc(void);
unsigned int mw_get_battery_adc_val(void);
-unsigned char mw_get_battery_percentage_from_val(unsigned int BatVal);
+uint8_t mw_get_battery_percentage_from_val(unsigned int BatVal);
+unsigned int mw_get_amblight_adc_val(void);
#endif
mw_acc_read(&x, &y, &z);
snprintf(tstr, 64, "x:%d y:%d z:%d\n", x,y,z);
debug_uart_tx(tstr);
+ } else if (c =='R') {
+ int16_t al;
+ al = mw_get_amblight_adc_val();
+ snprintf(tstr, 64, "light: %d\n", al);
+ debug_uart_tx(tstr);
} else if (c == 'b') {
debug_uart_tx("\nenabling BT\n");
mw_enable_bt();
oswald_draw_line(40, 82, 40, 30);
x = 41+25+((accel_data->x * 50) / (254));
- y = 31+25+((accel_data->y * 50) / (254));
+ y = 31+25-((accel_data->y * 50) / (254));
oswald_draw_pixel(x, y);
oswald_draw_pixel(x+1, y);
oswald_draw_pixel(x-1, y);