Skip to content

Commit

Permalink
Add schematics and additional pictures, reconfigure for using SPI0 wh…
Browse files Browse the repository at this point in the history
…ich is faster and more reliable.
  • Loading branch information
untoxa committed Aug 19, 2022
1 parent daddf84 commit d52fe89
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 11 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ set(TINYUSB_LIBNETWORKING_SOURCES
${PICO_TINYUSB_PATH}/lib/networking/rndis_reports.c
)

add_executable(${PROJECT_NAME} src/pico_gb_printer.c src/tusb_lwip_glue.c src/usb_descriptors.c ${TINYUSB_LIBNETWORKING_SOURCES})
add_executable(${PROJECT_NAME} src/pico_gb_printer.c src/tusb_lwip_glue.c src/usb_descriptors.c src/flasher.c ${TINYUSB_LIBNETWORKING_SOURCES})

pico_enable_stdio_usb(${PROJECT_NAME} 0)
pico_enable_stdio_uart(${PROJECT_NAME} 0)
target_include_directories(${PROJECT_NAME} PRIVATE ${LWIP_INCLUDE_DIRS} ${PICO_TINYUSB_PATH}/src ${PICO_TINYUSB_PATH}/lib/networking)
target_link_libraries(${PROJECT_NAME} pico_stdlib pico_multicore pico_unique_id hardware_spi tinyusb_device lwipallapps lwipcore)
target_link_libraries(${PROJECT_NAME} pico_stdlib pico_multicore pico_unique_id hardware_spi tinyusb_device lwipallapps lwipcore hardware_flash)
pico_add_extra_outputs(${PROJECT_NAME})
target_compile_definitions(${PROJECT_NAME} PRIVATE PICO_ENTER_USB_BOOT_ON_EXIT=1)
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,22 @@ Based on the original webserver for the PI Pico repo: https://github.com/maxnet/
Webserver example that came with TinyUSB slightly modified to run on a Raspberry Pi Pico.
Lets the Pico pretend to be a USB Ethernet device. Runs the webinterface at http://192.168.7.1/

I suggest to use this board: https://stacksmashing.gumroad.com/l/gb-link with PI Pico.

Special thanks to Raphael-Boichot, please check this repo: https://github.com/Raphael-Boichot/The-Arduino-SD-Game-Boy-Printer

## Schematics

You will need a Raspberry Pi, 1/2 of the game boy link cable and a four-channel 5v to 3.3v level shifter. Connect parts as shown:

<p align="center">
<img src="https://github.com/untoxa/pico-gb-printer/blob/main/screenshot.png?raw=true"/>
</p>

This is the example of the ready-to-use device:

<p align="center">
<img src="https://github.com/untoxa/pico-gb-printer/blob/main/device.jpg?raw=true"/>
</p>

## Build dependencies

### On Debian:
Expand Down
Binary file modified build/pico_gb_printer.uf2
Binary file not shown.
Binary file added device.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions include/flasher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef _FLASHER_H_INCLUDE_
#define _FLASHER_H_INCLUDE_

uint8_t * flash_address(uint32_t sector);
uint8_t * flash_read(uint8_t * dest, uint32_t sector, uint32_t len);
void flash_write(uint32_t sector, uint8_t * sour, uint32_t len);

#endif
Binary file added schematics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/flasher.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "pico/stdlib.h"
#include "hardware/flash.h"
#include <string.h>

extern uint8_t __flash_binary_end;

static inline size_t get_sector_offset(uint32_t sector) {
return (((size_t)(&__flash_binary_end - (uint8_t *)XIP_BASE) / FLASH_SECTOR_SIZE) + sector + 1) * FLASH_SECTOR_SIZE;
}

uint8_t * flash_address(uint32_t sector) {
return (uint8_t *)XIP_BASE + get_sector_offset(sector);
}

uint8_t * flash_read(uint8_t * dest, uint32_t sector, uint32_t len) {
return memcpy(dest, (uint8_t *)XIP_BASE + get_sector_offset(sector), len);
}

void flash_write(uint32_t sector, uint8_t * sour, uint32_t len) {
uint8_t buffer[FLASH_PAGE_SIZE];
size_t offset = get_sector_offset(sector);
flash_range_erase(offset, (len / FLASH_SECTOR_SIZE + 1) * FLASH_SECTOR_SIZE);
while (len) {
uint32_t sz = (len < FLASH_PAGE_SIZE) ? len : FLASH_PAGE_SIZE;
memcpy(buffer, sour, sz);
sour += sz;
flash_range_program(offset, buffer, sz);
offset += FLASH_PAGE_SIZE;
len -= sz;
}
}
19 changes: 12 additions & 7 deletions src/pico_gb_printer.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define USE_MULTICORE 1
#define USE_KEY 1
#define USE_SPI 0
#define USE_SPI 1

#include "pico/stdlib.h"
#include "pico/bootrom.h"
Expand All @@ -11,8 +11,8 @@
#include "hardware/spi.h"

#include "lwip/apps/fs.h"

#include "tusb_lwip_glue.h"
#include "flasher.h"

#define ENABLE_DEBUG false
#define BUFFER_SIZE_KB 176
Expand All @@ -33,12 +33,12 @@
#define PIN_SOUT 2

// SPI mode
#define SPI_PORT spi1
#define SPI_PORT spi0
#define SPI_BAUDRATE 64 * 1024 * 8

#define PIN_SPI_SCK 10
#define PIN_SPI_SOUT 11
#define PIN_SPI_SIN 12
#define PIN_SPI_SCK 2
#define PIN_SPI_SOUT 3
#define PIN_SPI_SIN 0

// "Tear" button
#define PIN_KEY 23
Expand Down Expand Up @@ -337,10 +337,15 @@ static inline void setup_sio() {
}

#if (USE_SPI==1)
static inline void retrigger_spi(spi_inst_t *spi) {
static inline void spi_off(spi_inst_t *spi) {
hw_clear_bits(&spi_get_hw(spi)->cr1, SPI_SSPCR1_SSE_BITS);
}
static inline void spi_on(spi_inst_t *spi) {
hw_set_bits(&spi_get_hw(spi)->cr1, SPI_SSPCR1_SSE_BITS);
}
static inline void retrigger_spi(spi_inst_t *spi) {
spi_off(spi), spi_on(spi);
}
#endif

#if (USE_MULTICORE==1)
Expand Down

0 comments on commit d52fe89

Please sign in to comment.