Skip to content

Commit e5ba160

Browse files
fintrosAlexey Spirkov
andauthored
Adds xdrive device support (#1005)
Co-authored-by: Alexey Spirkov <[email protected]>
1 parent 45d5aa2 commit e5ba160

16 files changed

+343
-10
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ fujinet_releases/*
5858
*~
5959
*.orig
6060
*.rej
61+
62+
# espressif managed components
63+
managed_components

boards/esp32-s3-xdrive-n4r2.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"build": {
3+
"arduino": {
4+
"ldscript": "esp32s3_out.ld"
5+
},
6+
"core": "esp32",
7+
"extra_flags": [
8+
"-DBOARD_HAS_PSRAM",
9+
"-DARDUINO_USB_MODE=1",
10+
"-DARDUINO_USB_CDC_ON_BOOT=1"
11+
],
12+
"f_cpu": "240000000L",
13+
"f_flash": "80000000L",
14+
"flash_mode": "qio",
15+
"mcu": "esp32s3",
16+
"variant": "esp32s3",
17+
"partitions": "fujinet_partitions_4MB_noupdate.csv"
18+
},
19+
"connectivity": [
20+
"wifi"
21+
],
22+
"debug": {
23+
"openocd_target": "esp32s3.cfg"
24+
},
25+
"frameworks": [
26+
"espidf"
27+
],
28+
"name": "ESP32-S3-XDRIVE N4R2",
29+
"upload": {
30+
"flash_size": "4MB",
31+
"maximum_ram_size": 327680,
32+
"maximum_size": 4194304,
33+
"use_1200bps_touch": true,
34+
"wait_for_upload_port": true,
35+
"require_upload_port": true,
36+
"speed": 460800
37+
},
38+
"url": "https://github.com/FujiNetWIFI/fujinet-firmware",
39+
"vendor": "FujiNet Project"
40+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[fujinet]
2+
build_platform = BUILD_ATARI
3+
build_bus = SIO
4+
build_board = fujinet-atari-esp32-s3-xdrive-n4r2
5+
6+
[env:fujinet-atari-esp32-s3-xdrive-n4r2]
7+
platform = espressif32@${fujinet.esp32_platform_version}
8+
platform_packages = ${fujinet.esp32_platform_packages}
9+
board = esp32-s3-xdrive-n4r2
10+
build_type = debug
11+
build_flags =
12+
${env.build_flags}
13+
-D PINMAP_ESP32S3_XDRIVE
14+
board_build.partitions = fujinet_partitions_4MB_noupdate.csv
15+

build_firmwarezip.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,25 @@ def makezip(source, target, env):
252252
"offset": "0xA70000"
253253
}
254254
]
255+
elif config[environment]['board'] == "esp32-s3-xdrive-n4r2":
256+
json_contents['files'] += [
257+
{
258+
"filename": "bootloader.bin",
259+
"offset": "0x0000"
260+
},
261+
{
262+
"filename": "partitions.bin",
263+
"offset": "0x8000"
264+
},
265+
{
266+
"filename": "firmware.bin",
267+
"offset": "0x10000"
268+
},
269+
{
270+
"filename": "littlefs.bin",
271+
"offset": "0x250000"
272+
}
273+
]
255274
# Save Release JSON
256275
with open('firmware/release.json', 'w') as f:
257276
f.write(json.dumps(json_contents, indent=4))
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
paths:
2+
# fonts in the root dir because of file name length issues
3+
font_path: /file?
4+
css_path: /file?css
5+
js_path: /file?js
6+
components:
7+
network: true
8+
hardware: true
9+
hosts_list: true
10+
mount_list: true
11+
printer_settings: true
12+
modem_settings: true
13+
hsio_settings: true
14+
timezone: true
15+
udp_stream: true
16+
program_recorder: true
17+
disk_swap: true
18+
boot_settings: true
19+
apetime: true
20+
cpm_settings: true
21+
pclink: true
22+
tweaks:
23+
# webui tweaks, if any
24+
config_ng: true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Name, Type, SubType, Offset, Size, Flags
2+
# Non-Volitile Storage
3+
nvs, data, nvs, 0x9000, 28K,
4+
# Main Application
5+
main, app, factory, 0x10000, 0x240000,
6+
# Flash Storage
7+
storage, data, littlefs, 0x250000, 0x1B0000

include/debug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// Use FujiNet debug serial output
2626
#include "../lib/hardware/fnUART.h"
2727
#define Serial fnUartDebug
28-
#ifdef PINMAP_RS232_S3
28+
#if defined(PINMAP_RS232_S3) /*|| defined(PINMAP_ESP32S3_XDRIVE)*/
2929
#define Debug_print(...) printf( __VA_ARGS__ )
3030
#define Debug_printf(...) printf( __VA_ARGS__ )
3131
#define Debug_println(...) do { printf(__VA_ARGS__); printf("\n"); } while (0)

include/pinmap.h

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "pinmap/rc2014spi_rev0.h"
3030
#include "pinmap/heathkit_h89.h"
3131
#include "pinmap/atari2600.h"
32+
#include "pinmap/esp32s3-xdrive.h"
3233

3334

3435
#ifndef PIN_DEBUG

include/pinmap/esp32s3-xdrive.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#ifdef PINMAP_ESP32S3_XDRIVE
2+
3+
#define IF_ENABLE_PIN GPIO_NUM_5
4+
5+
/* SD Card */
6+
#define PIN_CARD_DETECT GPIO_NUM_NC // GPIO_NUM_48 fnSystem.h
7+
#define PIN_CARD_DETECT_FIX GPIO_NUM_NC // fnSystem.h
8+
9+
#define PIN_SD_HOST_CS GPIO_NUM_21 // fnFsSD.cpp
10+
#define PIN_SD_HOST_MISO GPIO_NUM_16
11+
#define PIN_SD_HOST_MOSI GPIO_NUM_18
12+
#define PIN_SD_HOST_SCK GPIO_NUM_17
13+
14+
/* UART */
15+
#define PIN_UART0_RX GPIO_NUM_44 // fnUART.cpp
16+
#define PIN_UART0_TX GPIO_NUM_43
17+
#define PIN_UART1_RX GPIO_NUM_NC
18+
#define PIN_UART1_TX GPIO_NUM_NC
19+
#define PIN_UART2_RX GPIO_NUM_9
20+
#define PIN_UART2_TX GPIO_NUM_8
21+
22+
/* Buttons */
23+
#define PIN_BUTTON_A GPIO_NUM_34
24+
#define PIN_BUTTON_B GPIO_NUM_35
25+
#define PIN_BUTTON_C GPIO_NUM_NC
26+
27+
/* LEDs strip */
28+
#define PIN_LED_STRIP GPIO_NUM_33 // fnLedStrip.cpp
29+
#define LED_STRIP_COUNT 1
30+
31+
/* LEDs */
32+
#define PIN_LED_WIFI GPIO_NUM_NC // led.cpp
33+
#define PIN_LED_BUS GPIO_NUM_NC
34+
#define PIN_LED_BT GPIO_NUM_NC
35+
36+
/* Atari SIO Pins */
37+
#define PIN_INT GPIO_NUM_13 // sio.h
38+
#define PIN_PROC GPIO_NUM_12
39+
#define PIN_CKO GPIO_NUM_6
40+
#define PIN_CKI GPIO_NUM_7
41+
#define PIN_MTR GPIO_NUM_11
42+
#define PIN_CMD GPIO_NUM_10
43+
44+
45+
/* Audio Output */
46+
#define PIN_DAC1 GPIO_NUM_NC
47+
48+
#endif /* PINMAP_ESP32S3_XDRIVE */
49+

lib/hardware/fnLedStrip.cpp

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#include "fnLedStrip.h"
2+
#include "fnSystem.h"
3+
#include "../../include/pinmap.h"
4+
5+
#ifdef ESP_PLATFORM
6+
#if defined(PIN_LED_STRIP) && defined(LED_STRIP_COUNT)
7+
#include "led_strip.h"
8+
static led_strip_handle_t strip;
9+
#define HAVE_LED_STRIP
10+
#endif // defined(PIN_LED_STRIP) && defined(LED_STRIP_COUNT)
11+
#endif // ESP_PLATFORM
12+
13+
#define BLINKING_TIME 100
14+
15+
16+
void LedStripManager::setup()
17+
{
18+
r = g = b = 0;
19+
#ifdef HAVE_LED_STRIP
20+
// LED strip general initialization, according to your led board design
21+
led_strip_config_t strip_config = {
22+
.strip_gpio_num = PIN_LED_STRIP, // The GPIO that connected to the LED strip's data line
23+
.max_leds = LED_STRIP_COUNT, // The number of LEDs in the strip,
24+
.led_model = LED_MODEL_WS2812, // LED strip model
25+
.color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRB, // The color order of the strip: GRB
26+
.flags = {
27+
.invert_out = false, // don't invert the output signal
28+
}
29+
};
30+
31+
// LED strip backend configuration: RMT
32+
led_strip_rmt_config_t rmt_config = {
33+
.clk_src = RMT_CLK_SRC_DEFAULT, // different clock source can lead to different power consumption
34+
.resolution_hz = (10 * 1000 * 1000), // RMT counter clock frequency - 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution)
35+
.mem_block_symbols = 0, // let the driver choose a proper memory block size automatically
36+
.flags = {
37+
.with_dma = 0, // Using DMA can improve performance when driving more LEDs
38+
}
39+
};
40+
41+
// LED Strip object handle
42+
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &strip));
43+
44+
for(int i = 0; i < LED_STRIP_COUNT; i++)
45+
led_strip_set_pixel(strip, i, r, g, b);
46+
47+
led_strip_refresh(strip);
48+
#endif
49+
}
50+
51+
void LedStripManager::set(eLedID id, bool on)
52+
{
53+
#ifdef HAVE_LED_STRIP
54+
switch(id)
55+
{
56+
case LED_STRIP_BUS:
57+
g = on?brightness:0;
58+
break;
59+
case LED_STRIP_BT:
60+
r = on?brightness:0;
61+
break;
62+
case LED_STRIP_WIFI:
63+
b = on?brightness:0;
64+
break;
65+
};
66+
for(int i = 0; i < LED_STRIP_COUNT; i++)
67+
led_strip_set_pixel(strip, i, r, g, b);
68+
69+
led_strip_refresh(strip);
70+
#endif
71+
}
72+
73+
void LedStripManager::toggle(eLedID id)
74+
{
75+
#ifdef HAVE_LED_STRIP
76+
switch(id)
77+
{
78+
case LED_STRIP_BUS:
79+
g = brightness-g;
80+
break;
81+
case LED_STRIP_BT:
82+
r = brightness-r;
83+
break;
84+
case LED_STRIP_WIFI:
85+
b = brightness-b;
86+
break;
87+
};
88+
for(int i = 0; i < LED_STRIP_COUNT; i++)
89+
led_strip_set_pixel(strip, i, r, g, b);
90+
91+
led_strip_refresh(strip);
92+
#endif
93+
}
94+
95+
void LedStripManager::blink(eLedID led, int count)
96+
{
97+
for(int i = 0; i < count; i++)
98+
{
99+
toggle(led);
100+
fnSystem.delay(BLINKING_TIME);
101+
toggle(led);
102+
if(i < count - 1)
103+
fnSystem.delay(BLINKING_TIME);
104+
}
105+
}
106+
107+
bool LedStripManager::present()
108+
{
109+
#ifdef HAVE_LED_STRIP
110+
return true;
111+
#else
112+
return false;
113+
#endif
114+
}
115+
116+
LedStripManager fnLedStrip;

0 commit comments

Comments
 (0)