PowerBlocks SDK
 
Loading...
Searching...
No Matches
wiimote_hid.h
Go to the documentation of this file.
1
10
11#pragma once
12
15
16#include "powerblocks/input/wiimote/wiimote.h"
18
19#include "FreeRTOS.h"
20#include "semphr.h"
21
22#define WIIMOTE_REPORT_LEDS 0x11 // Set the leds on the controller
23#define WIIMOTE_REPORT_REPORT_MODE 0x12 // Used to make/configure reports
24#define WIIMOTE_REPORT_ENABLE_CAMERA_CLOCK 0x13 // Enables 24 MHz clock to the internal camera
25#define WIIMOTE_REPORT_STATUS 0x15 // Request status information
26#define WIIMOTE_REPORT_WRITE_MEMORY 0x16 // Writes to the internal memory of the wiimote
27#define WIIMOTE_REPORT_READ_MEMORY 0x17 // Request to read memory data
28#define WIIMOTE_REPORT_ENABLE_CAMERA 0x1A // Activates the camera enable line
29#define WIIMOTE_REPORT_STATUS_INFO 0x20 // Reply to status request, also when it changes states
30#define WIIMOTE_REPORT_READ_MEMORY_DATA 0x21 // Reply to the read memory report.
31#define WIIMOTE_REPORT_ACKNOWLEDGE_OUTPUT 0x22 // Required acknowledgement to write memory report
32#define WIIMOTE_REPORT_BUTTONS 0x30 // Core buttons data
33#define WIIMOTE_REPORT_BUTTONS_ACCL 0x31 // Core Buttons + Accelerometer
34#define WIIMOTE_REPORT_BUTTONS_EXT8 0x32 // Core Buttons + 8 Extension Bytes
35#define WIIMOTE_REPORT_BUTTONS_ACCL_IR12 0X33 // Core Buttons + Accelerometer + 8 Extension Bytes
36#define WIIMOTE_REPORT_BUTTONS_EXT19 0X34 // Core Buttons + 19 Extension Bytes
37#define WIIMOTE_REPORT_BUTTONS_ACCL_EXT16 0x35 // Core Buttons + Accelerometer + 16 Extension Bytes
38#define WIIMOTE_REPORT_BUTTONS_IR10_EXT9 0x36 // Core Buttons + 10 IR Bytes + 9 Extension Bytes
39#define WIIMOTE_REPORT_BUTTONS_ACCEL_IR10_EXT6 0x37 // Core Buttons + Accelerometer + 10 IR Bytes + 6 Extension Bytes
40#define WIIMOTE_REPORT_EXT21 0x3D // 21 Extension Bytes
41#define WIIMOTE_REPORT_INTERLEAVED_A 0x3E // Interleaved Buttons and Accelerometer with 36 IR
42#define WIIMOTE_REPORT_INTERLEAVED_B 0x3F // Other end of Interleaved Data
43
44typedef enum {
45 WIIMOTE_FLAGS_BATTERY_NEAR_EMPTY = 0X01,
46 WIIMOTE_FLAGS_EXTENSION_CONNECTED = 0X02,
47 WIIMOTE_FLAGS_SPEAKER_ENABLED = 0X04,
48 WIIMOTE_FLAGS_IR_CAMERA_ENABLED = 0X08,
49 WIIMOTE_FLAGS_LED1 = 0X10,
50 WIIMOTE_FLAGS_LED2 = 0X20,
51 WIIMOTE_FLAGS_LED3 = 0X40,
52 WIIMOTE_FLAGS_LEF4 = 0X80
53} wiimote_flags_t;
54
55// This is the core data structure of the wiimote
56// With all your wiimote information and status.
57typedef struct {
58 struct {
59 uint16_t core_buttons; // The main buttons of the wiimote. Only updated during status reports. So don't use.
60 wiimote_flags_t flags; // Contains LED and state information
61 uint8_t battery_level;
62 } core_state;
63
64 struct {
65 uint16_t accel_zero[3];
66 uint16_t accel_one[3];
67 } calibration;
68
69 const wiimote_extension_mapper_t* ext_mapper;
70
71 uint8_t report_type;
72 uint8_t data_report[42]; // Max report size is 21, but interleaved allows for 2 to make 1
74
75typedef struct {
76 int slot; // Wiimote slot, or -1 if there is not slot its been assigned to.
77
78 l2cap_device_t device;
79
80 l2cap_channel_t control_channel;
81 l2cap_channel_t interrupt_channel;
82
83 uint8_t wiimote_control_channel_buffer[16]; // This channel is barely used if at all.
84 uint8_t wiimote_interrupt_channel_buffer[256];
85
86 uint8_t set_report_mode;
87 uint8_t set_ir_mode;
88
89 // Internal state
90 SemaphoreHandle_t internal_state_lock;
91 wiimote_raw_t internal_state;
92
93 StaticSemaphore_t semaphore_data[1];
95
96// Attempts to connect to the bluetooth device and setup everything
97// Returns a bluetooth error code if failed
98extern int wiimote_hid_initialize(wiimote_hid_t* wiimote, const hci_discovered_device_info_t* discovery, int slot);
99
100// Closes a connection to a wiimote
101extern void wiimote_hid_close(wiimote_hid_t* wiimote);
102
103// Sets what data is reported back
104// You usually want to update the IR mode too.
105extern int wiimote_hid_set_report(wiimote_hid_t* wiimote, uint8_t report_type, bool update_ir_mode);
106
107// Driver filter callback
108// Will allow connection if a valid wiimote and a slot is available.
109extern bool wiimote_hid_driver_filter(const hci_discovered_device_info_t* device, const char* device_name);
110
111// Called to initiate a driver
112extern void* wiimote_hid_driver_initialize(const hci_discovered_device_info_t* device);
113
114// Called when the device needs to go
115extern void wiimote_hid_driver_free_device(void* instance);
Bluetooth HCI Driver.
Bluetooth L2CAP Layer.
Definition hci.h:27
Definition l2cap.h:45
Definition l2cap.h:73
Definition wiimote_extension.h:81
Definition wiimote_hid.h:75
Definition wiimote_hid.h:57
Handles wiimote extensions.