forked from rehius/usk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
5,133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Generated Cmake Pico project file | ||
|
||
cmake_minimum_required(VERSION 3.13) | ||
|
||
set(CMAKE_C_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_BUILD_TYPE MinSizeRel) | ||
|
||
# Pull in Raspberry Pi Pico SDK (must be before project) | ||
include(pico_sdk_import.cmake) | ||
|
||
project(usk C CXX ASM) | ||
|
||
# Initialise the Raspberry Pi Pico SDK | ||
pico_sdk_init() | ||
|
||
# Add executable. Default name is the project name, version 0.1 | ||
|
||
add_executable(usk main.c board_detect.c fuses.c pio_upload.c boot_detect.c config.c misc.c payload.c glitch.c) | ||
|
||
target_compile_definitions(usk PRIVATE PICO_NO_BINARY_INFO) | ||
|
||
pico_generate_pio_header(usk ${CMAKE_CURRENT_LIST_DIR}/ws2812.pio OUTPUT_DIR ${CMAKE_CURRENT_LIST_DIR}/generated) | ||
pico_generate_pio_header(usk ${CMAKE_CURRENT_LIST_DIR}/emmc.pio OUTPUT_DIR ${CMAKE_CURRENT_LIST_DIR}/generated) | ||
|
||
pico_set_program_name(usk "usk") | ||
pico_set_program_version(usk "2.7") | ||
|
||
pico_set_binary_type(usk no_flash) | ||
|
||
pico_enable_stdio_uart(usk 0) | ||
pico_enable_stdio_usb(usk 0) | ||
|
||
# Add the standard library to the build | ||
target_link_libraries(usk pico_stdlib) | ||
|
||
# Add any user requested libraries | ||
target_link_libraries(usk | ||
hardware_pio | ||
hardware_adc | ||
hardware_flash | ||
) | ||
|
||
pico_add_extra_outputs(usk) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
#include "pico/stdlib.h" | ||
#include "hardware/pio.h" | ||
#include "hardware/gpio.h" | ||
#include "hardware/adc.h" | ||
#include "pins.h" | ||
#include "ws2812.pio.h" | ||
#include "misc.h" | ||
#include "board_detect.h" | ||
|
||
extern int ws_pio_offset; | ||
|
||
enum board_type { | ||
BOARD_WS = 0, | ||
BOARD_XO, | ||
BOARD_IB, | ||
BOARD_PI, | ||
BOARD_SQ | ||
}; | ||
|
||
enum board_type cur_board = BOARD_WS; | ||
|
||
bool detect_by_pull_up(int frc_pin, int det_pin) | ||
{ | ||
bool result = false; | ||
if (frc_pin >= 0) | ||
gpio_init(frc_pin); | ||
gpio_init(det_pin); | ||
if (frc_pin >= 0) | ||
gpio_set_dir(frc_pin, true); | ||
gpio_pull_up(det_pin); | ||
sleep_us(15); | ||
result = !gpio_get(det_pin); | ||
gpio_deinit(det_pin); | ||
if (frc_pin >= 0) | ||
gpio_deinit(frc_pin); | ||
gpio_disable_pulls(det_pin); | ||
return result; | ||
} | ||
|
||
bool test_xiao() | ||
{ | ||
return detect_by_pull_up(1, 2); | ||
} | ||
|
||
bool test_itsy() | ||
{ | ||
return detect_by_pull_up(3, 2); | ||
} | ||
|
||
bool test_pico() | ||
{ | ||
return detect_by_pull_up(-1, 22); | ||
} | ||
|
||
bool test_ws() | ||
{ | ||
return detect_by_pull_up(-1, 25); | ||
} | ||
|
||
bool test_sqc() | ||
{ | ||
return detect_by_pull_up(-1, 17); | ||
} | ||
|
||
void detect_board() | ||
{ | ||
gpio_pull_down(PIN_GLI_WS); | ||
gpio_pull_down(PIN_GLI_PICO); | ||
gpio_pull_down(PIN_GLI_XIAO); | ||
gpio_pull_down(PIN_GLI_ITSY); | ||
gpio_disable_input_output(PIN_RST); | ||
if (test_ws()) { | ||
cur_board = BOARD_WS; | ||
} else if (test_xiao()) { | ||
cur_board = BOARD_XO; | ||
} else if (test_itsy()) { | ||
cur_board = BOARD_IB; | ||
} else if (test_pico()) { | ||
cur_board = BOARD_PI; | ||
} else if (test_sqc()) { | ||
cur_board = BOARD_SQ; | ||
} else { | ||
cur_board = BOARD_WS; | ||
} | ||
} | ||
|
||
int led_pin() | ||
{ | ||
switch(cur_board){ | ||
case BOARD_XO: | ||
return PIN_LED_XIAO; | ||
case BOARD_PI: | ||
return PIN_LED_PICO; | ||
case BOARD_IB: | ||
return PIN_LED_ITSY; | ||
default: | ||
return PIN_LED_WS; | ||
}; | ||
} | ||
|
||
int pwr_pin() | ||
{ | ||
switch(cur_board){ | ||
case BOARD_XO: | ||
return PIN_LED_PWR_XIAO; | ||
case BOARD_IB: | ||
return PIN_LED_PWR_ITSY; | ||
default: | ||
return 31; | ||
}; | ||
} | ||
|
||
int scl_pin() | ||
{ | ||
switch(cur_board){ | ||
case BOARD_XO: | ||
return PIN_SCL_XIAO; | ||
case BOARD_IB: | ||
return PIN_SCL_ITSY; | ||
case BOARD_PI: | ||
return PIN_SCL_PICO; | ||
case BOARD_SQ: | ||
return PIN_SCL_SQC; | ||
default: | ||
return PIN_SCL_WS; | ||
}; | ||
} | ||
|
||
int sda_pin() | ||
{ | ||
switch(cur_board){ | ||
case BOARD_XO: | ||
return PIN_SDA_XIAO; | ||
case BOARD_IB: | ||
return PIN_SDA_ITSY; | ||
case BOARD_PI: | ||
return PIN_SDA_PICO; | ||
case BOARD_SQ: | ||
return PIN_SDA_SQC; | ||
default: | ||
return PIN_SDA_WS; | ||
}; | ||
} | ||
|
||
int gli_pin() | ||
{ | ||
switch(cur_board){ | ||
case BOARD_XO: | ||
return PIN_GLI_XIAO; | ||
case BOARD_IB: | ||
return PIN_GLI_ITSY; | ||
case BOARD_PI: | ||
return PIN_GLI_PICO; | ||
default: | ||
return PIN_GLI_WS; | ||
}; | ||
} | ||
|
||
bool is_pico() | ||
{ | ||
return cur_board == BOARD_PI; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "stdbool.h" | ||
|
||
bool detect_by_pull_up(int frc_pin, int det_pin); | ||
|
||
void detect_board(); | ||
int gli_pin(); | ||
int pwr_pin(); | ||
int led_pin(); | ||
bool is_pico(); | ||
int scl_pin(); | ||
int sda_pin(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "hardware/clocks.h" | ||
#include "hardware/gpio.h" | ||
#include "hardware/pio.h" | ||
#include "pins.h" | ||
#include "pico/stdlib.h" | ||
#include "glitch.h" | ||
#include "misc.h" | ||
#include "fuses.h" | ||
|
||
bool mariko = true; | ||
bool board_detected = false; | ||
|
||
bool wait_for_boot(int timeout_ms) { | ||
absolute_time_t tio_full = make_timeout_time_ms(timeout_ms); | ||
absolute_time_t tio_cmd1 = tio_full; | ||
init_glitch_pio(); | ||
reset_cpu(); | ||
uint32_t word=0, last_word=0; | ||
bool was_read_zero = false; | ||
bool was_cmd1 = false; | ||
int reset_attempts = 0; | ||
|
||
while(!time_reached(tio_full)) { | ||
if (time_reached(tio_cmd1)) | ||
{ | ||
if (reset_attempts > 4) | ||
{ | ||
halt_with_error(0, 3); | ||
} | ||
reset_attempts++; | ||
reset_cpu(); | ||
tio_cmd1 = tio_full; | ||
} | ||
if(!pio_sm_is_rx_fifo_empty(pio1, 0)) | ||
{ | ||
word = pio_sm_get(pio1, 0); | ||
if (last_word == 0x41000000 && word == 0x00F9) // cmd1 request | ||
{ | ||
tio_cmd1 = make_timeout_time_ms(20); | ||
was_cmd1 = true; | ||
} | ||
else if (last_word == 0x00F9 && (word >> 24) == 0x3F) // cmd1 responce | ||
{ | ||
tio_cmd1 = tio_full; | ||
} | ||
else if (last_word == 0x51000000 && word == 0x0055) //read block 0 | ||
{ | ||
tio_full = make_timeout_time_ms(100); | ||
was_read_zero = true; | ||
} else if (was_read_zero && last_word == 0x4D000200 && word == 0x00B1) // read status - erista only | ||
{ | ||
mariko = false; | ||
} else if (last_word == 0x51000000 && word == 0x0147) // read block 1, can finish now | ||
{ | ||
deinit_glitch_pio(); | ||
return true; | ||
} | ||
last_word = word; | ||
} | ||
} | ||
if (was_read_zero) { | ||
halt_with_error(1, 3); | ||
} | ||
else if (was_cmd1) { | ||
halt_with_error(2, 3); | ||
} else { | ||
halt_with_error(3, 3); | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
bool wait_for_boot(int timeout_ms); | ||
|
||
// type of NS is detected in wait_for_boot | ||
extern bool mariko; |
Oops, something went wrong.