summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--main.c125
1 files changed, 88 insertions, 37 deletions
diff --git a/main.c b/main.c
index ef6da45..274711f 100644
--- a/main.c
+++ b/main.c
@@ -19,6 +19,13 @@
#include "tusb_desc.c"
+//#define DEBUG
+#ifdef DEBUG
+ #define dprintf(...) printf(__VA_ARGS__)
+#else
+ #define dprintf(...)
+#endif
+
#define COL_GRN 0x33000000
#define COL_RED 0x00330000
@@ -59,11 +66,11 @@ enum
const static uint8_t sr_pins[SR_PIN_CNT] =
{
- [SR_IN] = 9,
- [SR_nOE] = 10,
- [SR_RCLK] = 11,
- [SR_SCLK] = 12,
- [SR_nCLR] = 13,
+ [SR_IN] = 28, // rIN
+ [SR_nCLR] = 14, // rCLR
+ [SR_SCLK] = 13, // rSCLK
+ [SR_RCLK] = 12, // rRCLK
+ [SR_nOE] = 11, // rSOE
};
const static uint8_t sr_pins_def[SR_PIN_CNT] =
@@ -72,7 +79,7 @@ const static uint8_t sr_pins_def[SR_PIN_CNT] =
[SR_nOE] = 1,
[SR_RCLK] = 0,
[SR_SCLK] = 0,
- [SR_nCLR] = 1,
+ [SR_nCLR] = 0,
};
@@ -87,20 +94,20 @@ enum
const static uint8_t rom_pins[ROM_PIN_CNT] =
{
- [ROM_nWE] = 14,
- [ROM_nOE] = 15,
- [ROM_nCE] = 26,
+ [ROM_nCE] = 27, // rCS
+ [ROM_nOE] = 26, // rOE
+ [ROM_nWE] = 15, // rWE
};
const static uint8_t rom_pins_def[ROM_PIN_CNT] =
{
[ROM_nWE] = 1,
[ROM_nOE] = 1,
- [ROM_nCE] = 0,
+ [ROM_nCE] = 1,
};
-#define PIN_IO_OE 29
+#define PIN_IO_OE 10 // rDOE
#define PIN_IO_OE_DEF 1
const static uint8_t io_pins[8] =
@@ -111,8 +118,8 @@ const static uint8_t io_pins[8] =
5,
6,
7,
- 27,
- 28
+ 8,
+ 9
};
@@ -187,6 +194,37 @@ static void set_addr(uint16_t addr)
sleep_ns(24);
}
+static void send_byte(uint16_t addr, uint8_t data)
+{
+ set_addr(addr);
+
+ for(int k = 0; k < 8; k++)
+ gpio_put(io_pins[k], (data >> k) & 1);
+
+ sleep_ns(50);
+
+ gpio_put(rom_pins[ROM_nWE], 0);
+ sleep_ns(150);
+
+ gpio_put(rom_pins[ROM_nWE], 1);
+ sleep_ns(50);
+}
+
+static void chip_erase(void)
+{
+ writemode();
+ gpio_put(rom_pins[ROM_nOE], 1);
+
+ send_byte(0x5555, 0xAA);
+ send_byte(0x2AAA, 0x55);
+ send_byte(0x5555, 0x80);
+ send_byte(0x5555, 0xAA);
+ send_byte(0x2AAA, 0x55);
+ send_byte(0x5555, 0x10);
+
+ busy_wait_ms(20);
+}
+
void core1_main(void)
{
while(1)
@@ -197,6 +235,8 @@ void core1_main(void)
writemode();
gpio_put(rom_pins[ROM_nOE], 1);
+ if((pending % EEPROM_BLK_SZ) > 0) printf("core1: non-page write!\n");
+
int pages = (pending / EEPROM_BLK_SZ) + ((pending % EEPROM_BLK_SZ) ? 1 : 0);
for(int i = 0; i < pages; i++)
{
@@ -221,7 +261,7 @@ void core1_main(void)
busy_wait_ms(10);
}
- printf("core1: wrote %d bytes to %04x\n", pending, writeoffset);
+ dprintf("core1: wrote %d bytes to %04x\n", pending, writeoffset);
pending = 0;
mutex_exit(&busy_lock);
}
@@ -231,12 +271,15 @@ void core1_main(void)
int main(void)
{
board_init();
- tusb_init();
- stdio_init_all();
- gpio_init(PIN_RGB);
- gpio_set_dir(PIN_RGB, GPIO_OUT);
- gpio_put(PIN_RGB, 0);
+ for(int i = 0; i < ROM_PIN_CNT; i++)
+ {
+ gpio_init(rom_pins[i]);
+ gpio_set_dir(rom_pins[i], GPIO_OUT);
+ gpio_put(rom_pins[i], rom_pins_def[i]);
+ }
+
+ readmode();
gpio_init(PIN_IO_OE);
gpio_set_dir(PIN_IO_OE, GPIO_OUT);
@@ -249,14 +292,15 @@ int main(void)
gpio_put(sr_pins[i], sr_pins_def[i]);
}
- for(int i = 0; i < ROM_PIN_CNT; i++)
- {
- gpio_init(rom_pins[i]);
- gpio_set_dir(rom_pins[i], GPIO_OUT);
- gpio_put(rom_pins[i], rom_pins_def[i]);
- }
+ gpio_init(PIN_RGB);
+ gpio_set_dir(PIN_RGB, GPIO_OUT);
+ gpio_put(PIN_RGB, 0);
+
+ tusb_init();
+ stdio_init_all();
+
+ gpio_put(rom_pins[ROM_nCE], 0);
- readmode();
int sm = 0; // XXX: ???
uint32_t offset = pio_add_program(pio0, &ws2812_program);
@@ -270,10 +314,17 @@ int main(void)
multicore_reset_core1();
multicore_launch_core1(core1_main);
- sleep_ms(1000);
-
-
printf("Hell, world...\n");
+ printf("28C256 USB MSC. Firmware ver 1.0\n");
+ printf("2024 (C) dweller@cabin.digital\n\n");
+
+ /*
+ * TODO: SCSI erase/format?
+ printf("Erasing chip...\n");
+ chip_erase();
+ printf("Done!\n");
+ while(1);
+ */
uint32_t prev = access;
uint32_t start_ms = 0;
@@ -326,12 +377,12 @@ void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16
memcpy(product_id , pid, strlen(pid));
memcpy(product_rev, rev, strlen(rev));
- printf("scsi: inq\n");
+ dprintf("scsi: inq\n");
}
bool tud_msc_test_unit_ready_cb(uint8_t lun)
{
- printf("scsi: rdy\n");
+ dprintf("scsi: rdy\n");
return true;
}
@@ -341,12 +392,12 @@ void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_siz
*block_count = BLKS;
*block_size = BLK_SZ;
- printf("scsi: cap\n");
+ dprintf("scsi: cap\n");
}
bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject)
{
- printf("scsi: stop\n");
+ dprintf("scsi: stop\n");
if(load_eject)
{
@@ -367,7 +418,7 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff
int addr = (lba * BLK_SZ) + offset;
- printf("scsi: read @ %04X\n", addr);
+ dprintf("scsi: read @ %04X\n", addr);
readmode();
@@ -396,7 +447,7 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff
bool tud_msc_is_writable_cb(uint8_t lun)
{
- printf("scsi: rw?\n");
+ dprintf("scsi: rw?\n");
return true;
}
@@ -411,7 +462,7 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t*
writeoffset = (lba * BLK_SZ) + offset;
- printf("scsi: write req @ %04x\n", writeoffset);
+ dprintf("scsi: write req @ %04x\n", writeoffset);
memcpy(writebuf, buffer, bufsize);
pending = bufsize;
@@ -446,7 +497,7 @@ int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, u
}
}
- printf("scsi: generic\n");
+ dprintf("scsi: generic\n");
return resplen;
}