-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathtarget.h
More file actions
310 lines (271 loc) · 8.06 KB
/
target.h
File metadata and controls
310 lines (271 loc) · 8.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#ifndef _TARGET_H_
#define _TARGET_H_
//#define printf if(0) printf
#define OPTIONAL 2
//These are used to enable(1) or disable(2) the internal filesystem code */
#define USE_NATIVE_FS 0
#define USE_INTERNAL_FS 1
//Load target-specific include
#include "target_defs.h"
#include "target_all.h"
/* List of channels provided by the Tx */
#define CHANDEF(x) INP_##x,
#define UNDEF_INP
enum {
INP_NONE,
#include "capabilities.h"
INP_LAST,
};
#undef CHANDEF
#undef UNDEF_INP
/* List of buttons provided by the Tx */
#define BUTTONDEF(x) BUT_##x,
enum {
BUT_NONE,
#include "capabilities.h"
BUT_LAST,
};
#undef BUTTONDEF
#ifdef MODULAR
#define MODULE_CALLTYPE __attribute__((__long_call__))
#else
#define MODULE_CALLTYPE __attribute__ ((externally_visible))
#endif
#define CHAN_ButtonMask(btn) (btn ? (1 << (btn - 1)) : 0)
#define NUM_TX_INPUTS (INP_LAST - 1)
#define NUM_INPUTS (NUM_TX_INPUTS)
#define NUM_TX_BUTTONS (BUT_LAST - 1)
enum Radio {
CYRF6936,
A7105,
CC2500,
NRF24L01,
MULTIMOD,
RADIOLINK_CC2530,
R9M,
TX_MODULE_LAST,
};
#ifdef USE_PBM_IMAGE
#define IMG_EXT ".pbm"
#else
#define IMG_EXT ".bmp"
#endif
#define SWITCH_ADDRESS 0xFFFFFFFF
/* The following functions must be provided by every target */
/* General Functions */
void TxName(u8 *var, int len);
/* Backlight Functions */
void BACKLIGHT_Init();
void BACKLIGHT_Brightness(unsigned brightness);
/* Display Functions */
void LCD_Init();
void LCD_Contrast(unsigned contrast);
void LCD_ForceUpdate();
void LCD_CreateMappedWindow(unsigned val, unsigned x, unsigned y, unsigned w, unsigned h);
void LCD_SetMappedWindow(unsigned val);
void LCD_UnmapWindow(unsigned val);
unsigned LCD_GetMappedWindow();
void LCD_LoadFont(int idx, const char *file, int x_off, int y_off, int w, int h);
/* Primitives */
enum DrawDir {
DRAW_NWSE,
DRAW_SWNE,
};
void LCD_DrawPixel(unsigned int color);
void LCD_DrawMappedPixel(unsigned int color);
void LCD_DrawPixelXY(unsigned int x, unsigned int y, unsigned int color);
void LCD_DrawMappedPixelXY(unsigned int x, unsigned int y, unsigned int color);
void LCD_DrawStart(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, enum DrawDir dir);
void LCD_DrawMappedStart(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, enum DrawDir dir);
void LCD_DrawStop(void);
void LCD_DrawMappedStop(void);
void LCD_ShowVideo(u8 enable);
void VIDEO_SetChannel(int ch);
void VIDEO_Enable(int on);
void VIDEO_Contrast(int contrast);
void VIDEO_Brightness(int brightness);
u8 VIDEO_GetStandard(void);
void VIDEO_SetStandard(u8 standard);
/* Touchscreen */
struct touch {
u16 x;
u16 y;
u16 z1;
u16 z2;
};
void SPITouch_Init();
struct touch SPITouch_GetCoords();
int SPITouch_IRQ();
void SPITouch_Calibrate(s32 xscale, s32 yscale, s32 xoff, s32 yoff);
/* Buttons and switches */
void Initialize_ButtonMatrix();
u32 ScanButtons();
/* Rotary */
void ROTARY_Init();
u32 ROTARY_Scan();
/* Power functions */
void PWR_Init(void);
unsigned PWR_ReadVoltage(void);
int PWR_CheckPowerSwitch();
void PWR_Shutdown();
void PWR_Sleep();
/* Clock functions */
#define LOW_PRIORITY_MSEC 100
#define MEDIUM_PRIORITY_MSEC 5
enum MsecCallback {
MEDIUM_PRIORITY,
LOW_PRIORITY,
LAST_PRIORITY,
};
void CLOCK_Init(void);
MODULE_CALLTYPE u32 CLOCK_getms(void);
MODULE_CALLTYPE void CLOCK_StartTimer(unsigned us, u16 (*cb)(void));
MODULE_CALLTYPE void CLOCK_StopTimer();
void CLOCK_SetMsecCallback(int cb, u32 msec);
void CLOCK_ClearMsecCallback(int cb);
void CLOCK_StartWatchdog();
MODULE_CALLTYPE void CLOCK_ResetWatchdog();
MODULE_CALLTYPE void CLOCK_RunMixer();
MODULE_CALLTYPE void CLOCK_StartMixer();
typedef enum {
MIX_TIMER,
MIX_NOT_DONE,
MIX_DONE
} mixsync_t;
extern volatile mixsync_t mixer_sync;
/*PWM/PPM functions */
void PWM_Initialize();
void PWM_Stop();
void PWM_Set(int);
void PPM_Enable(unsigned low_time, volatile u16 *pulses, u8 num_pulses);
void PXX_Enable(u8 *packet);
/* PPM-In functions */
#define MAX_PPM_IN_CHANNELS 8
void PPMin_TIM_Init();
void PPMin_Start();
void PPMin_Stop();
/* Sticks */
void CHAN_Init();
s32 CHAN_ReadInput(int channel);
s32 CHAN_ReadRawInput(int channel);
extern void CHAN_SetSwitchCfg(const char *str);
extern void CHAN_SetButtonCfg(const char *str);
#define CHAN_ButtonIsPressed(buttons, btn) (buttons & (CHAN_ButtonMask(btn)))
/* SPI Flash */
void SPIFlash_Init();
u32 SPIFlash_ReadID();
void SPIFlash_EraseSector(u32 sectorAddress);
void SPIFlash_BulkErase();
void SPIFlash_WriteBytes(u32 writeAddress, u32 length, const u8 * buffer);
void SPIFlash_WriteByte(u32 writeAddress, const unsigned byte);
void SPIFlash_ReadBytes(u32 readAddress, u32 length, u8 * buffer);
int SPIFlash_ReadBytesStopCR(u32 readAddress, u32 length, u8 * buffer);
void SPI_FlashBlockWriteEnable(unsigned enable);
/* Sound */
void SOUND_Init();
void SOUND_SetFrequency(unsigned freq, unsigned volume);
void SOUND_Start(unsigned msec, u16 (*next_note_cb)(), u8 vibrate);
void SOUND_StartWithoutVibrating(unsigned msec, u16(*next_note_cb)());
void SOUND_Stop();
/* Vibrating motor */
void VIBRATINGMOTOR_Init();
void VIBRATINGMOTOR_Start();
void VIBRATINGMOTOR_Stop();
/* UART & Debug */
typedef enum {
UART_STOPBITS_1,
UART_STOPBITS_1_5,
UART_STOPBITS_2,
} uart_stopbits;
typedef enum {
UART_PARITY_EVEN,
UART_PARITY_ODD,
UART_PARITY_NONE,
} uart_parity;
typedef enum {
UART_DUPLEX_FULL,
UART_DUPLEX_HALF,
} uart_duplex;
void UART_Initialize();
void UART_Stop();
u8 UART_Send(u8 *data, u16 len);
void UART_SetDataRate(u32 bps);
void UART_SetFormat(int bits, uart_parity parity, uart_stopbits stopbits);
typedef void usart_callback_t(u8 ch, u8 status);
/* callback status byte bit fields */
#define UART_RX_RXNE (1 << 5) //USART_SR_RXNE - rx buffer not empty
#define UART_SR_ORE (1 << 3) //USART_SR_ORE - rx buffer overrun error
#define UART_SR_NE (1 << 2) //USART_SR_NE - noise error
#define UART_SR_FE (1 << 1) //USART_SR_FE - framing error
#define UART_SR_PE (1 << 0) //USART_SR_PE - parity error
void UART_StartReceive(usart_callback_t isr_callback);
void UART_StopReceive();
void UART_SetDuplex(uart_duplex duplex);
typedef void sser_callback_t(u8 data);
void SSER_StartReceive(sser_callback_t isr_callback);
void SSER_Initialize();
void SSER_Stop();
/* USB*/
void USB_Enable(unsigned use_interrupt);
void USB_Disable();
void USB_HandleISR();
void USB_Connect();
void HID_Enable();
void HID_Disable();
void MSC_Enable();
void MSC_Disable();
/* Filesystem */
int FS_Mount(void *FAT, const char *drive);
void FS_Unmount();
int FS_OpenDir(const char *path);
int FS_ReadDir(char *path);
void FS_CloseDir();
MODULE_CALLTYPE void _usleep(u32 usec);
void _msleep(u32 msec);
#define usleep _usleep
/* Abstract bootloader access */
enum {
BL_ID = 0,
};
u8 *BOOTLOADER_Read(int idx);
#define PROTO_HAS_CYRF6936
#define PROTO_HAS_A7105
#define PROTO_HAS_CC2500
#define PROTO_HAS_NRF24L01
//Ensure functions are loaded for protocol modules
void SPI_ProtoInit();
void SPI_AVRProgramInit();
MODULE_CALLTYPE int SPI_ConfigSwitch(unsigned csn_high, unsigned csn_low);
MODULE_CALLTYPE int SPI_ProtoGetPinConfig(int module, int state);
u32 AVR_StartProgram();
int AVR_Erase();
int AVR_Program(u32 address, u8 *data, int pagesize);
int AVR_SetFuses();
int AVR_ResetFuses();
int AVR_VerifyFuses();
int AVR_Verify(u8 *data, int size);
struct mcu_pin;
void MCU_InitModules();
int MCU_SetPin(struct mcu_pin *, const char *name);
const char *MCU_GetPinName(char *str, struct mcu_pin *);
MODULE_CALLTYPE void MCU_SerialNumber(u8 *var, int len);
#if defined HAS_4IN1_FLASH && HAS_4IN1_FLASH
void SPISwitch_Init();
unsigned SPISwitch_Present();
unsigned SPISwitch_FlashPresent();
void SPISwitch_CS_HI(int module);
void SPISwitch_CS_LO(int module);
void SPISwitch_UseFlashModule();
void SPISwitch_CYRF6936_RESET(int state);
void SPISwitch_NRF24L01_CE(int state);
#else
#define SPISwitch_Init()
#define SPISwitch_Present() 0
#define SPISwitch_FlashPresent() 0
#define SPISwitch_CS_HI(module)
#define SPISwitch_CS_LO(module)
#define SPISwitch_UseFlashModule()
#define SPISwitch_CYRF6936_RESET(state)
#define SPISwitch_NRF24L01_CE(state)
#endif
#endif