00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00017 #include "sceptre.h"
00018 #include "bluetooth.h"
00019 #include "btm222.h"
00020
00022 #define BLUETOOTH_PIN 18
00023 #define BLUETOOTH_POWER_OFF IOSET1 = (1<<BLUETOOTH_PIN)
00024 #define BLUETOOTH_POWER_ON IOCLR1 = (1<<BLUETOOTH_PIN)
00025
00026
00032 void bluetooth_power(int power)
00033 {
00034 if (power==BLUETOOTH_OFF) BLUETOOTH_POWER_OFF;
00035 else BLUETOOTH_POWER_ON;
00036 }
00037
00038
00045 bool_t bluetooth_init(int baudrate)
00046 {
00047 IODIR1 |= (1<<BLUETOOTH_PIN);
00048 bluetooth_power(BLUETOOTH_OFF);
00049 return uart1_init(baudrate,8,'n',1);
00050 }
00051
00052
00059 bool_t bluetooth_set_friendly_name(char *p_name)
00060 {
00061 return btm222_command("N=",p_name,BTM222_MAX_PEER_ID);
00062 }
00063
00064
00071 bool_t bluetooth_set_pin(char *p_pin)
00072 {
00073 return btm222_command("P=",p_pin,4);
00074 }
00075
00076
00086 int bluetooth_send(char *p_data, int data_size)
00087 {
00088 return 0;
00089 }
00090
00091
00099 uint8_t bluetooth_scan(void)
00100 {
00101 return btm222_seek_devices();
00102 }
00103
00104
00117 bool_t bluetooth_connect(bool_t as_slave, char *p_pin, uint8_t device, uint32_t timeout_ms, bool_t reconnect)
00118 {
00119 if (as_slave==true)
00120 {
00121 btm222_write_command((uint8_t*)BTM_CMD_ROLE_SLAVE);
00122 btm222_write_command((uint8_t*)BTM_CMD_CONNECT_AUTO);
00123 }
00124 else
00125 {
00126 btm222_write_command((uint8_t*)BTM_CMD_ROLE_MASTER);
00127 btm222_write_command((uint8_t*)BTM_CMD_CONNECT_NOAUTO);
00128 }
00129 bluetooth_set_pin(p_pin);
00130 return btm222_wait_for_connect(timeout_ms,reconnect);
00131 }
00132
00133
00139 bool_t bluetooth_is_connected(void)
00140 {
00141 return btm222_is_connected();
00142 }
00143
00144
00152 void bluetooth_get_module_info(void)
00153 {
00154 btm222_get_all_parameters();
00155 }