You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

74 lines
1.5 KiB

#include "print.h"
#include "usb-base-drv.h"
static uint16_t wait_for_state(const uint8_t loop_counter, uint8_t state, const uint8_t desired_state) __sdcccall(1) {
uint16_t r = state;
for (uint8_t i = 0; i < loop_counter; i++) {
if (state == desired_state)
break;
if (i & 1)
print_string("\b $");
else
print_string("\b*$");
r = usb_init(state);
state = r & 255;
}
return r;
}
static void _chnative_init(bool forced) {
uint8_t state = 0;
uint16_t r;
const uint8_t loop_counter = forced ? 40 : 5;
print_string("\r\nCH376: *$");
r = wait_for_state(loop_counter, state, 1);
state = r & 255;
print_string("\bPRESENT (VER $");
r = usb_init(state);
state = r & 255;
if (state != 2) {
print_string("\rCH376: $");
print_string("VERSION FAILURE\r\n$");
return;
}
print_hex(r >> 8);
print_string("); $");
print_string("USB: *$");
r = wait_for_state(loop_counter, state, 3);
state = r & 255;
if (state == 2) {
print_string("\bDISCONNECTED$");
return;
}
print_string("\bCONNECTED$");
// enumerate....
r = usb_init(state);
state = r & 255;
for (uint8_t i = 0; i < loop_counter; i++) {
if (r >> 8 != 0)
break;
print_string(".$");
r = usb_init(state);
state = r & 255;
}
}
void chnative_init_force(void) { _chnative_init(true); }
void chnative_init(void) { _chnative_init(false); }