Rework for custom pcb
This commit is contained in:
parent
e79ff575e6
commit
83e3b51b40
@ -33,6 +33,7 @@ target_link_libraries(mtgcard PUBLIC
|
|||||||
pico_stdlib
|
pico_stdlib
|
||||||
hardware_spi
|
hardware_spi
|
||||||
hardware_dma
|
hardware_dma
|
||||||
|
hardware_clocks
|
||||||
tinyusb_device
|
tinyusb_device
|
||||||
tinyusb_board
|
tinyusb_board
|
||||||
pico_unique_id
|
pico_unique_id
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
class CardSlot
|
class CardSlot
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static constexpr size_t FLASH_SIZE_MB = 2;
|
static constexpr size_t FLASH_SIZE_MB = 8;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CardSlot(lib::Flash& flash, uint16_t card_index);
|
CardSlot(lib::Flash& flash, uint16_t card_index);
|
||||||
|
|||||||
@ -15,6 +15,7 @@ extern "C"
|
|||||||
#define CFG_TUD_VENDOR 1
|
#define CFG_TUD_VENDOR 1
|
||||||
|
|
||||||
#define CFG_TUD_VENDOR_RX_BUFSIZE 0
|
#define CFG_TUD_VENDOR_RX_BUFSIZE 0
|
||||||
|
#define CFG_TUD_VENDOR_TX_BUFSIZE 256
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,8 +44,8 @@ Flash::Flash(uint8_t sck, uint8_t tx, uint8_t rx, uint8_t cs, int baudrate) :
|
|||||||
|
|
||||||
void Flash::read_page(uint16_t page_index)
|
void Flash::read_page(uint16_t page_index)
|
||||||
{
|
{
|
||||||
const uint8_t cmd[5] = { CMD_READ, static_cast<uint8_t>(page_index >> 8),
|
const uint8_t cmd[4] = { CMD_READ, static_cast<uint8_t>(page_index >> 8),
|
||||||
static_cast<uint8_t>(page_index), 0, 0 };
|
static_cast<uint8_t>(page_index), 0 };
|
||||||
|
|
||||||
gpio_put(cs, false);
|
gpio_put(cs, false);
|
||||||
spi_write_blocking(spi, cmd, 4);
|
spi_write_blocking(spi, cmd, 4);
|
||||||
@ -92,6 +92,7 @@ void Flash::write_enable()
|
|||||||
gpio_put(cs, false);
|
gpio_put(cs, false);
|
||||||
spi_write_blocking(spi, &cmd, 1);
|
spi_write_blocking(spi, &cmd, 1);
|
||||||
gpio_put(cs, true);
|
gpio_put(cs, true);
|
||||||
|
sleep_us(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Flash::wait_done()
|
void Flash::wait_done()
|
||||||
|
|||||||
54
src/main.cpp
54
src/main.cpp
@ -4,6 +4,7 @@
|
|||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "pixelstream.h"
|
#include "pixelstream.h"
|
||||||
|
|
||||||
|
#include <hardware/clocks.h>
|
||||||
#include <pico/binary_info.h>
|
#include <pico/binary_info.h>
|
||||||
#include <pico/stdlib.h>
|
#include <pico/stdlib.h>
|
||||||
#include <tusb.h>
|
#include <tusb.h>
|
||||||
@ -17,21 +18,24 @@ bi_decl(bi_program_feature_group(0x1111, 0, "Display Pinout"));
|
|||||||
bi_decl(bi_ptr_int32(0x1111, 0, DISPLAY_SCK, 2));
|
bi_decl(bi_ptr_int32(0x1111, 0, DISPLAY_SCK, 2));
|
||||||
bi_decl(bi_ptr_int32(0x1111, 0, DISPLAY_TX, 3));
|
bi_decl(bi_ptr_int32(0x1111, 0, DISPLAY_TX, 3));
|
||||||
bi_decl(bi_ptr_int32(0x1111, 0, DISPLAY_CS, 5));
|
bi_decl(bi_ptr_int32(0x1111, 0, DISPLAY_CS, 5));
|
||||||
bi_decl(bi_ptr_int32(0x1111, 0, DISPLAY_DC, 6));
|
bi_decl(bi_ptr_int32(0x1111, 0, DISPLAY_DC, 4));
|
||||||
|
|
||||||
bi_decl(bi_program_feature_group(0x1111, 1, "Flash Pinout"));
|
bi_decl(bi_program_feature_group(0x1111, 1, "Flash Pinout"));
|
||||||
bi_decl(bi_ptr_int32(0x1111, 1, FLASH_SCK, 26));
|
bi_decl(bi_ptr_int32(0x1111, 1, FLASH_SCK, 10));
|
||||||
bi_decl(bi_ptr_int32(0x1111, 1, FLASH_TX, 27));
|
bi_decl(bi_ptr_int32(0x1111, 1, FLASH_TX, 11));
|
||||||
bi_decl(bi_ptr_int32(0x1111, 1, FLASH_RX, 28));
|
bi_decl(bi_ptr_int32(0x1111, 1, FLASH_RX, 12));
|
||||||
bi_decl(bi_ptr_int32(0x1111, 1, FLASH_CS, 29));
|
bi_decl(bi_ptr_int32(0x1111, 1, FLASH_CS, 9));
|
||||||
|
bi_decl(bi_ptr_int32(0x1111, 1, FLASH_IO_2, 13));
|
||||||
|
bi_decl(bi_ptr_int32(0x1111, 1, FLASH_IO_3, 14));
|
||||||
|
|
||||||
bi_decl(bi_program_feature_group(0x1111, 2, "Buttons"));
|
bi_decl(bi_program_feature_group(0x1111, 2, "Buttons"));
|
||||||
bi_decl(bi_ptr_int32(0x1111, 2, BUTTON_LEFT, 8));
|
bi_decl(bi_ptr_int32(0x1111, 2, BUTTON_LEFT, 15));
|
||||||
bi_decl(bi_ptr_int32(0x1111, 2, BUTTON_MIDDLE, 0));
|
bi_decl(bi_ptr_int32(0x1111, 2, BUTTON_MIDDLE, 16));
|
||||||
bi_decl(bi_ptr_int32(0x1111, 2, BUTTON_RIGHT, 20));
|
bi_decl(bi_ptr_int32(0x1111, 2, BUTTON_RIGHT, 17));
|
||||||
|
|
||||||
Display display(DISPLAY_SCK, DISPLAY_TX, DISPLAY_CS, DISPLAY_DC, 120000000);
|
Display display(DISPLAY_SCK, DISPLAY_TX, DISPLAY_CS, DISPLAY_DC,
|
||||||
Flash flash(FLASH_SCK, FLASH_TX, FLASH_RX, FLASH_CS, 70000000);
|
100 * 1000 * 1000);
|
||||||
|
Flash flash(FLASH_SCK, FLASH_TX, FLASH_RX, FLASH_CS, 25 * 1000 * 1000);
|
||||||
|
|
||||||
enum class RX
|
enum class RX
|
||||||
{
|
{
|
||||||
@ -66,12 +70,25 @@ struct
|
|||||||
int32_t card_index = 0;
|
int32_t card_index = 0;
|
||||||
} rx;
|
} rx;
|
||||||
|
|
||||||
|
volatile uint8_t debug_requested = false;
|
||||||
|
|
||||||
constexpr int MS_BUTTON_TIMEOUT = 500;
|
constexpr int MS_BUTTON_TIMEOUT = 500;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
set_sys_clock_khz(200 * 1000, false);
|
||||||
|
|
||||||
|
gpio_set_function(FLASH_IO_2, GPIO_FUNC_SIO);
|
||||||
|
gpio_set_function(FLASH_IO_3, GPIO_FUNC_SIO);
|
||||||
|
|
||||||
|
gpio_set_dir(FLASH_IO_2, GPIO_OUT);
|
||||||
|
gpio_set_dir(FLASH_IO_3, GPIO_OUT);
|
||||||
|
|
||||||
|
gpio_put(FLASH_IO_2, 1);
|
||||||
|
gpio_put(FLASH_IO_3, 1);
|
||||||
|
|
||||||
gpio_set_function(BUTTON_LEFT, GPIO_FUNC_SIO);
|
gpio_set_function(BUTTON_LEFT, GPIO_FUNC_SIO);
|
||||||
gpio_set_function(BUTTON_MIDDLE, GPIO_FUNC_SIO);
|
gpio_set_function(BUTTON_MIDDLE, GPIO_FUNC_SIO);
|
||||||
gpio_set_function(BUTTON_RIGHT, GPIO_FUNC_SIO);
|
gpio_set_function(BUTTON_RIGHT, GPIO_FUNC_SIO);
|
||||||
@ -130,6 +147,15 @@ int main()
|
|||||||
menus::get_current_menu()->onTick(dt);
|
menus::get_current_menu()->onTick(dt);
|
||||||
|
|
||||||
previous_time = current;
|
previous_time = current;
|
||||||
|
|
||||||
|
if (debug_requested > 0 && tud_vendor_write_available() > 0)
|
||||||
|
{
|
||||||
|
flash.read_page((debug_requested - 1) * CardSlot::TOTAL_PAGE_COUNT);
|
||||||
|
tud_vendor_write(flash.page(), Flash::Page::SIZE);
|
||||||
|
tud_vendor_write_flush();
|
||||||
|
sleep_ms(500);
|
||||||
|
debug_requested -= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,6 +177,14 @@ void tud_vendor_rx_cb(uint8_t itf, const uint8_t* buffer, uint16_t bufsize)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// special command to debug flash
|
||||||
|
if (buffer[0] == 0x69)
|
||||||
|
{
|
||||||
|
debug_requested = CardSlot::MAX_CARDS;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
rx.state = RX::GETTING_CMC;
|
rx.state = RX::GETTING_CMC;
|
||||||
|
|
||||||
rx.card_index = CardSlot::get_unused(flash);
|
rx.card_index = CardSlot::get_unused(flash);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user