Skip to content

Commit

Permalink
merge rehius' changes for rp2040-tiny LED compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
DefenderOfHyrule committed Oct 31, 2024
1 parent 00db7fa commit c6647c1
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 24 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ jobs:
- name: Build busk
run: |
# Backup and modify memmap_default.ld for busk build
cp $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_standard_link/memmap_default.ld $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_standard_link/memmap_default.ld.bak
sed -i 's/RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k/RAM(rwx) : ORIGIN = 0x20038000, LENGTH = 32k/g' $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_standard_link/memmap_default.ld
cp $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_crt0/rp2040/memmap_default.ld $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_crt0/rp2040/memmap_default.ld.bak
sed -i 's/RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k/RAM(rwx) : ORIGIN = 0x20038000, LENGTH = 32k/g' $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_crt0/rp2040/memmap_default.ld
mkdir -p $GITHUB_WORKSPACE/build/busk
cd $GITHUB_WORKSPACE/build/busk
cmake $GITHUB_WORKSPACE/busk
make
make clean
cd $GITHUB_WORKSPACE
# Restore original memmap_default.ld from backup
rm -f $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_standard_link/memmap_default.ld
mv $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_standard_link/memmap_default.ld.bak $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_standard_link/memmap_default.ld
rm -f $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_crt0/rp2040/memmap_default.ld
mv $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_crt0/rp2040/memmap_default.ld.bak $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_crt0/rp2040/memmap_default.ld
- name: Build usk
run: |
Expand Down
41 changes: 27 additions & 14 deletions board_detect.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@ enum board_type {
BOARD_XO,
BOARD_IB,
BOARD_PI,
BOARD_SQ
BOARD_SQ,
BOARD_WT
};

enum board_type cur_board = BOARD_WS;

bool detect_by_pull_up(int frc_pin, int det_pin)
bool detect_by_pull(int frc_pin, int det_pin, bool up)
{
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);
gpio_set_pulls(det_pin, up, !up);
sleep_us(15);
result = !gpio_get(det_pin);
result = gpio_get(det_pin) ^ up;
gpio_deinit(det_pin);
if (frc_pin >= 0)
gpio_deinit(frc_pin);
Expand All @@ -39,27 +40,32 @@ bool detect_by_pull_up(int frc_pin, int det_pin)

bool test_xiao()
{
return detect_by_pull_up(1, 2);
return detect_by_pull(1, 2, 1);
}

bool test_itsy()
{
return detect_by_pull_up(3, 2);
return detect_by_pull(3, 2, 1);
}

bool test_pico()
{
return detect_by_pull_up(-1, 22);
return detect_by_pull(-1, 22, 1);
}

bool test_ws()
{
return detect_by_pull_up(-1, 25);
return detect_by_pull(-1, 25, 1);
}

bool test_wt()
{
return detect_by_pull(-1, 16, 0);
}

bool test_sqc()
{
return detect_by_pull_up(-1, 17);
return detect_by_pull(-1, 17, 1);
}

void detect_board()
Expand All @@ -79,6 +85,8 @@ void detect_board()
cur_board = BOARD_PI;
} else if (test_sqc()) {
cur_board = BOARD_SQ;
} else if (test_wt()) {
cur_board = BOARD_WT;
} else {
cur_board = BOARD_WS;
}
Expand All @@ -95,7 +103,7 @@ int led_pin()
return PIN_LED_ITSY;
default:
return PIN_LED_WS;
};
};
}

int pwr_pin()
Expand All @@ -107,7 +115,7 @@ int pwr_pin()
return PIN_LED_PWR_ITSY;
default:
return 31;
};
};
}

int scl_pin()
Expand All @@ -123,7 +131,7 @@ int scl_pin()
return PIN_SCL_SQC;
default:
return PIN_SCL_WS;
};
};
}

int sda_pin()
Expand All @@ -139,7 +147,7 @@ int sda_pin()
return PIN_SDA_SQC;
default:
return PIN_SDA_WS;
};
};
}

int gli_pin()
Expand All @@ -153,10 +161,15 @@ int gli_pin()
return PIN_GLI_PICO;
default:
return PIN_GLI_WS;
};
};
}

bool is_pico()
{
return cur_board == BOARD_PI;
}

bool is_tiny()
{
return cur_board == BOARD_WT;
}
5 changes: 3 additions & 2 deletions board_detect.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "stdbool.h"

bool detect_by_pull_up(int frc_pin, int det_pin);
bool detect_by_pull(int frc_pin, int det_pin, bool up);

void detect_board();
int gli_pin();
int pwr_pin();
int led_pin();
bool is_pico();
bool is_tiny();
int scl_pin();
int sda_pin();
int sda_pin();
2 changes: 1 addition & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define OFFSET_MAX 6950

#define VER_HI 2
#define VER_LO 77
#define VER_LO 78

bool is_configured();
void init_config();
Expand Down
9 changes: 8 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,20 @@ int main()
init_fuses();
// LED & glitch & emmc PIO
upload_pio();
if (is_tiny())
{
gpio_put(led_pin(), 0);
sleep_us(100);
put_pixel(0);
sleep_us(100);
}
// check if this is the very first start
if (watchdog_caused_reboot() && boot_try == 0)
{
halt_with_error(1, 1);
}
// is chip reset required
bool force_button = detect_by_pull_up(1, 0);
bool force_button = detect_by_pull(1, 0, 1);
// start LED
put_pixel(PIX_gre);
// test pins
Expand Down
10 changes: 8 additions & 2 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ void finish_pins_except_leds() {
}

void finish_pins_leds() {
gpio_disable_input_output(led_pin());
if (!is_tiny())
{
gpio_disable_input_output(led_pin());
}
gpio_disable_input_output(pwr_pin());
}

Expand Down Expand Up @@ -125,7 +128,10 @@ void put_pixel(uint32_t pixel_rgb)
pio_sm_put_blocking(pio0, 3, pixel_grb << 8u);
sleep_us(50);
pio_sm_set_enabled(pio0, 3, false);
gpio_init(led_pin());
if (!is_tiny())
{
gpio_init(led_pin());
}
}

void gpio_disable_input_output(int pin)
Expand Down

0 comments on commit c6647c1

Please sign in to comment.