Skip to content

Commit f237ca0

Browse files
committed
fix nova90 menu control
1 parent 65efe33 commit f237ca0

5 files changed

Lines changed: 228 additions & 92 deletions

File tree

src/camera.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,19 +432,22 @@ void camera_button_op(uint8_t op) {
432432
if (camera_type == CAMERA_TYPE_RUNCAM_NOVA_90) {
433433
switch (op) {
434434
case BTN_UP:
435-
RUNCAM_Write(RUNCAM_NOVA_90, 0x90, 0x02);
435+
RUNCAM_Write8(RUNCAM_NOVA_90, 0x90, 0x02);
436436
break;
437437
case BTN_DOWN:
438-
RUNCAM_Write(RUNCAM_NOVA_90, 0x90, 0x03);
438+
RUNCAM_Write8(RUNCAM_NOVA_90, 0x90, 0x03);
439439
break;
440440
case BTN_LEFT:
441-
RUNCAM_Write(RUNCAM_NOVA_90, 0x90, 0x04);
441+
RUNCAM_Write8(RUNCAM_NOVA_90, 0x90, 0x04);
442442
break;
443443
case BTN_RIGHT:
444-
RUNCAM_Write(RUNCAM_NOVA_90, 0x90, 0x05);
444+
RUNCAM_Write8(RUNCAM_NOVA_90, 0x90, 0x05);
445445
break;
446446
case BTN_ENTER:
447-
RUNCAM_Write(RUNCAM_NOVA_90, 0x90, 0x01);
447+
LED_BLUE_OFF;
448+
WAIT(100);
449+
LED_BLUE_ON;
450+
RUNCAM_Write8(RUNCAM_NOVA_90, 0x90, 0x01);
448451
break;
449452
case BTN_MID:
450453
// TODO

src/i2c.c

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ void I2C_start() {
4747
SCL_SET(0);
4848
DELAY_Q;
4949
}
50+
void I2C_start_cs() {
51+
if (I2C_EN != 1)
52+
return;
53+
54+
SDA_SET(1);
55+
DELAY_Q;
56+
57+
SCL_SET(1);
58+
while (SCL_GET() != 1)
59+
SCL_SET(1);
60+
DELAY_Q;
61+
62+
SDA_SET(0);
63+
DELAY_Q;
64+
DELAY_Q;
65+
66+
SCL_SET(0);
67+
DELAY_Q;
68+
}
5069

5170
void I2C_stop() {
5271
if (I2C_EN != 1)
@@ -63,6 +82,22 @@ void I2C_stop() {
6382
DELAY_Q;
6483
}
6584

85+
void I2C_stop_cs() {
86+
if (I2C_EN != 1)
87+
return;
88+
89+
SDA_SET(0);
90+
DELAY_Q;
91+
92+
while (SCL_GET() != 1)
93+
SCL_SET(1);
94+
DELAY_Q;
95+
96+
SDA_SET(1);
97+
DELAY_Q;
98+
DELAY_Q;
99+
}
100+
66101
uint8_t I2C_ack() {
67102
uint8_t ret;
68103

@@ -83,6 +118,27 @@ uint8_t I2C_ack() {
83118
return ret;
84119
}
85120

121+
uint8_t I2C_ack_cs() {
122+
uint8_t ret;
123+
124+
if (I2C_EN != 1)
125+
return 1;
126+
127+
SDA_SET(1);
128+
DELAY_Q;
129+
130+
while (SCL_GET() != 1)
131+
SCL_SET(1);
132+
ret = SDA_GET();
133+
DELAY_Q;
134+
DELAY_Q;
135+
136+
SCL_SET(0);
137+
DELAY_Q;
138+
139+
return ret;
140+
}
141+
86142
uint8_t I2C_write_byte(uint8_t val) {
87143
uint8_t i;
88144

@@ -110,6 +166,34 @@ uint8_t I2C_write_byte(uint8_t val) {
110166

111167
return i;
112168
}
169+
uint8_t I2C_write_byte_cs(uint8_t val) {
170+
uint8_t i;
171+
172+
if (I2C_EN != 1)
173+
return 1;
174+
175+
for (i = 0; i < 8; i++) {
176+
if (val >> 7)
177+
SDA_SET(1);
178+
else
179+
SDA_SET(0);
180+
DELAY_Q;
181+
182+
while (SCL_GET() != 1)
183+
SCL_SET(1);
184+
DELAY_Q;
185+
DELAY_Q;
186+
187+
SCL_SET(0);
188+
DELAY_Q;
189+
190+
val <<= 1;
191+
}
192+
193+
i = I2C_ack();
194+
195+
return i;
196+
}
113197

114198
uint8_t I2C_Write8(uint8_t slave_addr, uint8_t reg_addr, uint8_t val) {
115199
uint8_t slave = slave_addr << 1;
@@ -234,6 +318,43 @@ uint8_t I2C_read_byte(uint8_t no_ack) {
234318

235319
return val;
236320
}
321+
uint8_t I2C_read_byte_cs(uint8_t no_ack) {
322+
uint8_t i;
323+
uint8_t val = 0;
324+
325+
if (I2C_EN != 1)
326+
return 0;
327+
328+
for (i = 0; i < 8; i++) {
329+
DELAY_Q;
330+
while (SCL_GET() != 1)
331+
SCL_SET(1);
332+
333+
val <<= 1;
334+
val |= SDA_GET();
335+
336+
DELAY_Q;
337+
DELAY_Q;
338+
339+
SCL_SET(0);
340+
DELAY_Q;
341+
}
342+
343+
// master ack
344+
SDA_SET(no_ack);
345+
DELAY_Q;
346+
while (SCL_GET() != 1)
347+
SCL_SET(1);
348+
DELAY_Q;
349+
DELAY_Q;
350+
351+
SCL_SET(0);
352+
DELAY_Q;
353+
354+
SDA_SET(1);
355+
356+
return val;
357+
}
237358

238359
uint8_t I2C_Read8(uint8_t slave_addr, uint8_t reg_addr) {
239360
uint8_t slave, val;
@@ -367,6 +488,29 @@ uint8_t RUNCAM_Write(uint8_t cam_id, uint32_t addr, uint32_t val) {
367488
return 0;
368489
}
369490

491+
uint8_t RUNCAM_Write8(uint8_t cam_id, uint32_t addr, uint32_t val) {
492+
uint8_t value;
493+
494+
I2C_start(); // start
495+
496+
value = I2C_write_byte(cam_id); // slave
497+
if (value) {
498+
I2C_stop();
499+
return 1;
500+
}
501+
value = addr & 0xFF; // ADDR[7:0]
502+
I2C_write_byte(value);
503+
504+
value = val & 0xFF; // DATA[7:0]
505+
I2C_write_byte(value);
506+
507+
I2C_stop(); // stop
508+
509+
WAIT(10);
510+
511+
return 0;
512+
}
513+
370514
uint32_t RUNCAM_Read(uint8_t cam_id, uint32_t addr) {
371515
uint8_t value;
372516
uint32_t ret = 0;
@@ -408,6 +552,47 @@ uint32_t RUNCAM_Read(uint8_t cam_id, uint32_t addr) {
408552

409553
return ret;
410554
}
555+
uint32_t RUNCAM_Read_cs(uint8_t cam_id, uint32_t addr) {
556+
uint8_t value;
557+
uint32_t ret = 0;
558+
559+
I2C_start_cs(); // start
560+
561+
I2C_write_byte_cs(cam_id); // slave
562+
563+
I2C_write_byte_cs(0x13); // read cmd
564+
565+
value = (addr >> 16) & 0xFF; // ADDR[23:16]
566+
I2C_write_byte_cs(value);
567+
568+
value = (addr >> 8) & 0xFF; // ADDR[15:8]
569+
I2C_write_byte_cs(value);
570+
571+
value = addr & 0xFF; // ADDR[7:0]
572+
I2C_write_byte_cs(value);
573+
574+
I2C_start_cs(); // start
575+
576+
I2C_write_byte_cs(cam_id | 0x01); // slave | 0x01
577+
578+
value = I2C_read_byte_cs(0); // read DATA[31:24]
579+
ret = (ret << 8) | value;
580+
581+
value = I2C_read_byte_cs(0); // read DATA[23:16]
582+
ret = (ret << 8) | value;
583+
584+
value = I2C_read_byte_cs(0); // read DATA[15:8]
585+
ret = (ret << 8) | value;
586+
587+
value = I2C_read_byte_cs(1); // read DATA[7:0]
588+
ret = (ret << 8) | value;
589+
590+
I2C_stop_cs(); // stop
591+
592+
WAIT(10);
593+
594+
return ret;
595+
}
411596

412597
/*
413598
[return]

src/i2c.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ uint16_t I2C_Read16(uint8_t slave_addr, uint16_t reg_addr);
1414
uint16_t I2C_Read16_a8(uint8_t slave_addr, uint8_t reg_addr);
1515

1616
uint8_t RUNCAM_Write(uint8_t cam_id, uint32_t addr, uint32_t val);
17+
uint8_t RUNCAM_Write8(uint8_t cam_id, uint32_t addr, uint32_t val);
1718
uint32_t RUNCAM_Read(uint8_t cam_id, uint32_t addr);
19+
uint32_t RUNCAM_Read_cs(uint8_t cam_id, uint32_t addr);
1820
uint8_t RUNCAM_Read_Write(uint8_t cam_id, uint32_t addr, uint32_t val);
1921
uint8_t RUNCAM_Detect(uint8_t cam_id);
2022
#endif /* __I2C_H_ */

src/msp_displayport.c

Lines changed: 25 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ uint8_t msp_read_one_frame() {
225225
static uint8_t crc = 0;
226226
static uint16_t cmd_u16 = 0;
227227
static uint16_t len_u16 = 0;
228-
uint32_t r;
229228

230229
uint8_t i, ret, full_frame, rx;
231230

@@ -244,58 +243,6 @@ uint8_t msp_read_one_frame() {
244243
if (rx == MSP_HEADER_FRAMER) {
245244
ptr = 0;
246245
state = MSP_HEADER_M;
247-
} else {
248-
switch (rx) {
249-
case 'w':
250-
case 'W':
251-
LED_BLUE_OFF;
252-
WAIT(200);
253-
LED_BLUE_ON;
254-
RUNCAM_Write(RUNCAM_NOVA_90, 0x90, 0x02); // up
255-
break;
256-
case 's':
257-
case 'S':
258-
LED_BLUE_OFF;
259-
WAIT(200);
260-
LED_BLUE_ON;
261-
RUNCAM_Write(RUNCAM_NOVA_90, 0x90, 0x03); // down
262-
break;
263-
case 'a':
264-
case 'A':
265-
LED_BLUE_OFF;
266-
WAIT(200);
267-
LED_BLUE_ON;
268-
RUNCAM_Write(RUNCAM_NOVA_90, 0x90, 0x04); // left
269-
break;
270-
case 'd':
271-
case 'D':
272-
LED_BLUE_OFF;
273-
WAIT(200);
274-
LED_BLUE_ON;
275-
RUNCAM_Write(RUNCAM_NOVA_90, 0x90, 0x05); // right
276-
break;
277-
case 'e':
278-
case 'E':
279-
LED_BLUE_OFF;
280-
WAIT(200);
281-
LED_BLUE_ON;
282-
RUNCAM_Write(RUNCAM_NOVA_90, 0x90, 0x01); // enter
283-
break;
284-
case 'r': // read camera reg
285-
r = RUNCAM_Read(RUNCAM_NOVA_90, 0x50);
286-
if (r) {
287-
_outchar((r >> 24) & 0xff);
288-
_outchar((r >> 16) & 0xff);
289-
_outchar((r >> 8) & 0xff);
290-
_outchar((r >> 0) & 0xff);
291-
LED_BLUE_OFF;
292-
WAIT(500);
293-
LED_BLUE_ON;
294-
}
295-
break;
296-
default:
297-
break;
298-
}
299246
}
300247
break;
301248

@@ -1860,25 +1807,35 @@ void update_cms_menu(uint16_t roll, uint16_t pitch, uint16_t yaw, uint16_t throt
18601807
}
18611808

18621809
case CMS_ENTER_CAM: {
1863-
if (VirtualBtn == BTN_ENTER)
1810+
if (VirtualBtn == BTN_ENTER) {
18641811
cms_cnt++;
1865-
else
1812+
if (cms_cnt == 5) {
1813+
disp_mode = DISPLAY_CMS;
1814+
clear_screen();
1815+
if (camera_type == CAMERA_TYPE_UNKNOWN ||
1816+
camera_type == CAMERA_TYPE_OUTDATED) {
1817+
camera_select_menu_init();
1818+
camera_selected = 0;
1819+
cms_state = CMS_SELECT_CAM;
1820+
cms_cnt = 0;
1821+
} else if (camera_type == CAMERA_TYPE_RUNCAM_NOVA_90) {
1822+
clear_screen();
1823+
camera_menu_mode_exit_note();
1824+
RUNCAM_Write8(RUNCAM_NOVA_90, 0x90, 0x01); // enter
1825+
} else {
1826+
camera_menu_init();
1827+
cms_state = CMS_CAM;
1828+
cms_cnt = 0;
1829+
}
1830+
}
1831+
} else if (camera_type == CAMERA_TYPE_RUNCAM_NOVA_90 && cms_cnt > 5 && VirtualBtn == BTN_MID) {
1832+
cms_state = CMS_CAM;
1833+
cms_cnt = 0;
1834+
} else {
18661835
cms_state = CMS_OSD;
1867-
1868-
if (cms_cnt == 5) {
18691836
cms_cnt = 0;
1870-
disp_mode = DISPLAY_CMS;
1871-
clear_screen();
1872-
if (camera_type == CAMERA_TYPE_UNKNOWN ||
1873-
camera_type == CAMERA_TYPE_OUTDATED) {
1874-
camera_select_menu_init();
1875-
camera_selected = 0;
1876-
cms_state = CMS_SELECT_CAM;
1877-
} else {
1878-
camera_menu_init();
1879-
cms_state = CMS_CAM;
1880-
}
18811837
}
1838+
18821839
break;
18831840
}
18841841

0 commit comments

Comments
 (0)