Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Olimex ESP32-SBC-FabGL board #338

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions Extras/PC Emulator BASIC Programs/CH32GPIO.BAS
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

REM QBASIC program to control CH32V003 I/O expander inside PC Emulator

DECLARE FUNCTION HexByte$ (I)
DECLARE FUNCTION INT$ (I, L)
DECLARE FUNCTION ch32Available ()
DECLARE FUNCTION ch32VersionMinor ()
DECLARE FUNCTION ch32VersionMajor ()
DECLARE SUB gpioSelect (gpio)
DECLARE SUB gpioConfig (cfg)
DECLARE SUB gpioSet (level)
DECLARE FUNCTION gpioGet ()

CLS

REM check for I/O available
IF ch32Available = 0 THEN
PRINT "CH32V003 expander not available on this board!"
END
END IF

PRINT "CH32V003 expander firmware version "; INT$(ch32VersionMajor, 0); "."; INT$(ch32VersionMinor, 0); " found"

PRINT "Configure GPIO 6 as input pull-down"
gpioSelect (6)
gpioConfig (1)

PRINT "Configure GPIO 7 as output"
gpioSelect (7)
gpioConfig (0)

PRINT "Press any key to stop"

LOCATE 10, 1
WHILE LEN(INKEY$) = 0
gpioSet (1)
t = TIMER
WHILE TIMER - t < 1: WEND

gpioSet (0)
t = TIMER
WHILE TIMER - t < 1: WEND
WEND

FUNCTION HexByte$ (I)
HexByte$ = RIGHT$("00" + HEX$(I), 2)
END FUNCTION

FUNCTION INT$ (I, L)
R$ = LTRIM$(STR$(I))
IF L <> 0 THEN
R$ = RIGHT$(STRING$(L, " ") + R$, L)
END IF
INT$ = R$
END FUNCTION

FUNCTION ch32Available
ch32Available = (INP(&HF0) AND 1)
END FUNCTION

FUNCTION ch32VersionMinor
ch32VersionMinor = INP(&HFE)
END FUNCTION

FUNCTION ch32VersionMajor
ch32VersionMajor = INP(&HFF)
END FUNCTION

SUB gpioSelect (gpio)
OUT &HF1, gpio
END SUB

SUB gpioConfig (cfg)
OUT &HF2, cfg
END SUB

FUNCTION gpioGet
gpioGet = INP(&HF3)
END FUNCTION

SUB gpioSet (level)
OUT &HF3, level
END SUB
100 changes: 100 additions & 0 deletions Extras/PC Emulator BASIC Programs/CH32I2C.BAS
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@

REM QBASIC program to control CH32V003 I/O expander inside PC Emulator

DECLARE FUNCTION HexByte$ (i)
DECLARE FUNCTION INT$ (i, l)
DECLARE FUNCTION ch32Available ()
DECLARE FUNCTION ch32VersionMinor ()
DECLARE FUNCTION ch32VersionMajor ()
DECLARE SUB i2cInit (clock)
DECLARE SUB i2cSlave (slave)
DECLARE FUNCTION i2cReadReg (reg)
DECLARE SUB i2cWriteReg (reg, value)

CLS

REM check for I/O available
IF ch32Available = 0 THEN
PRINT "CH32V003 expander not available on this board!"
END
END IF

PRINT "CH32V003 expander firmware version "; INT$(ch32VersionMajor, 0); "."; INT$(ch32VersionMinor, 0); " found"

PRINT "Configure I2C clock to 300 KHz"
i2cInit (300)

PRINT "Configure I2C slave Nunchuk "
CALL i2cSlave(&H52)
CALL i2cWriteReg(&HF0, &H55)

PRINT "Press any key to stop"

LOCATE 10, 1
PRINT "Move the joystick..."
WHILE LEN(INKEY$) = 0
LOCATE 11, 1
PRINT "X = "; INT$(i2cReadReg(0), 3)
LOCATE 11, 10
PRINT "Y = "; INT$(i2cReadReg(1), 3)
WEND

REM CLS

LOCATE 3, 1
PRINT "Configure I2C slave RTC "
CALL i2cSlave(&H68)

WHILE LEN(INKEY$) = 0
LOCATE 10, 1
CALL i2cWriteReg(&HE, &H3C)
PRINT "Time "; HexByte$(i2cReadReg(2)); ":"; HexByte$(i2cReadReg(1)); ":"; HexByte$(i2cReadReg(0));
LOCATE 11, 1
PRINT "Temperature "; INT$(i2cReadReg(17), 0); "."; INT$(i2cReadReg(18) / 256 * 100, 0); CHR$(248); "C "
WEND

FUNCTION HexByte$ (i)
HexByte$ = RIGHT$("00" + HEX$(i), 2)
END FUNCTION

FUNCTION INT$ (i, l)
R$ = LTRIM$(STR$(i))
IF l <> 0 THEN
R$ = RIGHT$(STRING$(l, " ") + R$, l)
END IF
INT$ = R$
END FUNCTION

FUNCTION ch32Available
ch32Available = (INP(&HF0) AND 1)
END FUNCTION

FUNCTION ch32VersionMinor
ch32VersionMinor = INP(&HFE)
END FUNCTION

FUNCTION ch32VersionMajor
ch32VersionMajor = INP(&HFF)
END FUNCTION

SUB i2cInit (clock)
REM LSB
OUT &HF4, (clock MOD 256)
REM MSB
OUT &HF5, (clock \ 256)
END SUB

SUB i2cSlave (slave)
OUT &HF6, slave
END SUB

FUNCTION i2cReadReg (reg)
OUT &HF7, reg
i2cReadReg = INP(&HF8)
END FUNCTION

SUB i2cWriteReg (reg, value)
OUT &HF7, reg
OUT &HF8, value
END SUB

97 changes: 97 additions & 0 deletions Extras/PC Emulator BASIC Programs/CH32SPI.BAS
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@

REM QBASIC program to control CH32V003 I/O expander inside PC Emulator

DECLARE FUNCTION HexByte$ (I)
DECLARE FUNCTION INT$ (I, L)
DECLARE FUNCTION ch32Available ()
DECLARE FUNCTION ch32VersionMinor ()
DECLARE FUNCTION ch32VersionMajor ()
DECLARE SUB spiClock (clock)
DECLARE SUB spiMode (mode)
DECLARE FUNCTION spiTransfer8 (I)
DECLARE FUNCTION spiTransfer16 (I)

CLS

REM check for I/O available
IF ch32Available = 0 THEN
PRINT "CH32V003 expander not available on this board!"
END
END IF

PRINT "CH32V003 expander firmware version "; INT$(ch32VersionMajor, 0); "."; INT$(ch32VersionMinor, 0); " found"

PRINT "Configure SPI mode 3"
spiMode (3)

PRINT "Configure SPI clock to 50 KHz"
spiClock (50)

PRINT "Press any key to stop"

LOCATE 10, 1
WHILE LEN(INKEY$) = 0
LOCATE 10, 1
IF spiTransfer16(&H8200) AND 1 THEN
PRINT "X "; INT$(spiTransfer16(&H8300), 5)
END IF

LOCATE 10, 10
IF spiTransfer16(&H8400) AND 1 THEN
PRINT "Y "; INT$(spiTransfer16(&H8500), 5)
END IF

LOCATE 10, 20
IF spiTransfer16(&H8600) AND 1 THEN
PRINT "Z "; INT$(spiTransfer16(&H8700), 5)
END IF

PRINT "Temperature "; INT$(spiTransfer16(&H8800) / 2 - 30, 0); CHR$(248); "C "
WEND

FUNCTION HexByte$ (I)
HexByte$ = RIGHT$("00" + HEX$(I), 2)
END FUNCTION

FUNCTION INT$ (I, L)
R$ = LTRIM$(STR$(I))
IF L <> 0 THEN
R$ = RIGHT$(STRING$(L, " ") + R$, L)
END IF
INT$ = R$
END FUNCTION

FUNCTION ch32Available
ch32Available = (INP(&HF0) AND 1)
END FUNCTION

FUNCTION ch32VersionMinor
ch32VersionMinor = INP(&HFE)
END FUNCTION

FUNCTION ch32VersionMajor
ch32VersionMajor = INP(&HFF)
END FUNCTION

SUB spiMode (mode)
OUT &HF9, mode
END SUB

SUB spiClock (clock)
OUT &HFA, 50
END SUB

FUNCTION spiTransfer8 (I)
OUT &HFB, I
T = TIMER
WHILE TIMER - T < .1: WEND
spiTransfer8 = INP(&HFB)
END FUNCTION

FUNCTION spiTransfer16 (I)
OUT &HFC, (I MOD 256)
OUT &HFD, (I \ 256)
T = TIMER
WHILE TIMER - T < .1: WEND
spiTransfer16 = INP(&HFC) + INP(&HFD) * 256
END FUNCTION
54 changes: 52 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
You can support development by purchasing my own [development board](https://www.tindie.com/products/24612/) and [Serial Terminal](https://www.tindie.com/products/26801/).
You may also support me donating hardware (boards, lab instruments, etc...).

=================================================================================
======================================================

License terms:

Expand All @@ -25,7 +25,57 @@ Please contact fdivitto2013@gmail.com if you need a commercial license.

**Please don't remove copyright and/or original author from FabGL examples (ie from screens, dialogs, etc..), even from derived works which use examples as base.**

=================================================================================
========================================

## How to install ##

### Set up the Arduino environment ###

1. Install and start Arduino IDE, get it from: https://www.arduino.cc/en/software

2. Add the esp32 board support by Espressif using the Board Manager (Tools > Board > Board Manager and search for "esp32"). Use the package called “esp32” by Esoressif Systems and use the version selector to load a version 2.x.x! IMPORTANT! At the time of writing this, the FabGL library is NOT compatible with version 3.x.x or newer of the package. From the drop-down menu select version 2.0.x, we used 2.0.11.

3. The Olimex fork of FabGL adds support for the ESP32-SBC-FabGL board and needs to be installed as a local library. You'll also need to first uninstall Fabrizio's FabGL library if it's already installed.
- Go to the Olimex FabGLrepo at GitHub: https://github.com/OLIMEX/FabGL
- Click "Download ZIP" from the green "Code" drop-down button, top-right. Save the ZIP file as "Olimex-FabGL.zip" so you don't get confused with Fabrizio's library and repo.
- Unzip and copy the contents to a new folder in the "Documents\Arduino\libraries" folder (e.g. "C:\Users\username\Documents\Arduino\libraries\Olimex-FabGL").

4. Close Arduino IDE. The next time the IDE is started, the local Olimex FabGL library will be available for use.

### Compile and download examples to ESP32-SBC-FabGL ###

1. Connect the ESP32-SBC-FabGL board to your desktop PC using a USB cable. The USB-C port on the board serves as both power and data.

2. Start Arduino IDE.

3. Verify the Olimex FabGL library is loaded by:

- Opening the Library Manager (Tools > Manage Libraries).
- Typing "FabGL" in to the "filter" textbox.
- Changing the "Type" to "Installed".
- It should list "FabGL 1.0.9" (at the time of this writing) as one of the installed libraries.

5. Select a FabGL demo from (File > Examples > FabGL). The FabGL examples will be at the bottom of a lengthy list.

6. Configure the board.
- Select the "ESP32 Dev Module" board (Tools > Board > esp32 > ESP32 Dev Module).
- Set the board port to upload to (Tools > Port > COM#).
- Set the partition scheme (Tools > Partition > Huge APP).
- Disable PSRAM (Tools > PSRAM > Disabled).
- Set the Upload Speed (Tools > Upload Speed > 921600).
- If an upload error occurs, lower the transfer speed.

8. Edit the demo if needed. Most demos are well-commented on what has to be edited. Some demos require also preparing an SD card or else in specific manner.

9. Compile and upload to the board (Sketch > Upload).

- If all goes well, the ESP32-SBC-FabGL board will reboot after the compilation and upload complete.
- If the wireless parameters were not set, a prompt asking to configure the wireless connection will appear.
- After that, the boot menu should show.

If you have compilation problems with most of the examples you probably installed latest version of espressif package for ESP32. The most important part is to use ESP32 package version older than 3.x.x ESP32 package (we used Espressif 2.0.11). Also do NOT use the “Arduino ESP32 Boards” package! Use the “esp32” package by espressif systems!

=======================================


FabGL is mainly a Graphics Library for ESP32. It implements several display drivers (VGA output, PAL/NTSC Color Composite, I2C and SPI displays).
Expand Down
Loading