-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 290f74c
Showing
7 changed files
with
940 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# ez80zdi library | ||
|
||
> This library was extracted from [agon-recovery](https://github.com/envenomator/agon-recovery) tool. | ||
## Overview | ||
|
||
This libary provides a way to use ez80 ZDI interface ESP32 microcontroller. | ||
|
||
## Usage | ||
|
||
```c++ | ||
#include "ez80zdi.h" | ||
#include "ez80cpu.h" | ||
|
||
|
||
ZDI* zdi; | ||
CPU* cpu; | ||
|
||
void init_ez80(); | ||
|
||
void setup() { | ||
zdi = new ZDI(ZDI_TCKPIN, ZDI_TDIPIN); | ||
cpu = new CPU(zdi); | ||
|
||
init_ez80(); | ||
} | ||
|
||
void init_ez80() { | ||
cpu->setBreak(); | ||
cpu->setADLmode(true); | ||
cpu->instruction_di(); | ||
|
||
// configure cpu | ||
// set stack | ||
cpu->sp(0xBFFFF); | ||
// set PC to some program | ||
cpu->pc(0x40000); | ||
|
||
cpu->setContinue(); // start cpu after break | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "ez80zdi", | ||
"version": "1.0.0", | ||
"description": "A library for the EZ80 ZDI interface", | ||
"keywords": "ez80, zdi", | ||
"repository": | ||
{ | ||
"type": "git", | ||
"url": "https://github.com/mikolajmikolajczyk/ez80zdi.git" | ||
}, | ||
"authors": | ||
[ | ||
{ | ||
"name": "Jeroen Venema", | ||
"url": "https://github.com/envenomator/agon-recovery" | ||
}, | ||
{ | ||
"name": "Mikołaj Mikołajczyk", | ||
"email": "mikolaj@mikolajczyk.org", | ||
"url": "https://mikolajczyk.org", | ||
"maintainer": true | ||
} | ||
], | ||
"license": "MIT", | ||
"frameworks": "*", | ||
"platforms": "espressif32" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#ifndef esp32_io_h | ||
#define esp32_io_h | ||
|
||
#include <stdint.h> | ||
|
||
static inline __attribute__((always_inline)) | ||
uint32_t directRead(uint32_t pin) | ||
{ | ||
#if CONFIG_IDF_TARGET_ESP32C3 | ||
return (GPIO.in.val >> pin) & 0x1; | ||
#else // plain ESP32 | ||
if ( pin < 32 ) | ||
return (GPIO.in >> pin) & 0x1; | ||
else if ( pin < 46 ) | ||
return (GPIO.in1.val >> (pin - 32)) & 0x1; | ||
#endif | ||
|
||
return 0; | ||
} | ||
|
||
static inline __attribute__((always_inline)) | ||
void directWriteLow(uint32_t pin) | ||
{ | ||
#if CONFIG_IDF_TARGET_ESP32C3 | ||
GPIO.out_w1tc.val = ((uint32_t)1 << pin); | ||
#else // plain ESP32 | ||
if ( pin < 32 ) | ||
GPIO.out_w1tc = ((uint32_t)1 << pin); | ||
else if ( pin < 46 ) | ||
GPIO.out1_w1tc.val = ((uint32_t)1 << (pin - 32)); | ||
#endif | ||
} | ||
|
||
static inline __attribute__((always_inline)) | ||
void directWriteHigh(uint32_t pin) | ||
{ | ||
#if CONFIG_IDF_TARGET_ESP32C3 | ||
GPIO.out_w1ts.val = ((uint32_t)1 << pin); | ||
#else // plain ESP32 | ||
if ( pin < 32 ) | ||
GPIO.out_w1ts = ((uint32_t)1 << pin); | ||
else if ( pin < 46 ) | ||
GPIO.out1_w1ts.val = ((uint32_t)1 << (pin - 32)); | ||
#endif | ||
} | ||
|
||
static inline __attribute__((always_inline)) | ||
void directModeInput(uint32_t pin) | ||
{ | ||
#if CONFIG_IDF_TARGET_ESP32C3 | ||
GPIO.enable_w1tc.val = ((uint32_t)1 << (pin)); | ||
#else | ||
if ( digitalPinIsValid(pin) ) | ||
{ | ||
#if ESP_IDF_VERSION_MAJOR < 4 // IDF 3.x ESP32/PICO-D4 | ||
uint32_t rtc_reg(rtc_gpio_desc[pin].reg); | ||
|
||
if ( rtc_reg ) // RTC pins PULL settings | ||
{ | ||
ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_gpio_desc[pin].mux); | ||
ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_gpio_desc[pin].pullup | rtc_gpio_desc[pin].pulldown); | ||
} | ||
#endif | ||
// Input | ||
if ( pin < 32 ) | ||
GPIO.enable_w1tc = ((uint32_t)1 << pin); | ||
else | ||
GPIO.enable1_w1tc.val = ((uint32_t)1 << (pin - 32)); | ||
} | ||
#endif | ||
} | ||
|
||
static inline __attribute__((always_inline)) | ||
void directModeOutput(uint32_t pin) | ||
{ | ||
#if CONFIG_IDF_TARGET_ESP32C3 | ||
GPIO.enable_w1ts.val = ((uint32_t)1 << (pin)); | ||
#else | ||
if ( digitalPinIsValid(pin) && pin <= 33 ) // pins above 33 can be only inputs | ||
{ | ||
#if ESP_IDF_VERSION_MAJOR < 4 // IDF 3.x ESP32/PICO-D4 | ||
uint32_t rtc_reg(rtc_gpio_desc[pin].reg); | ||
|
||
if ( rtc_reg ) // RTC pins PULL settings | ||
{ | ||
ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_gpio_desc[pin].mux); | ||
ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_gpio_desc[pin].pullup | rtc_gpio_desc[pin].pulldown); | ||
} | ||
#endif | ||
// Output | ||
if ( pin < 32 ) | ||
GPIO.enable_w1ts = ((uint32_t)1 << pin); | ||
else // already validated to pins <= 33 | ||
GPIO.enable1_w1ts.val = ((uint32_t)1 << (pin - 32)); | ||
} | ||
#endif | ||
} | ||
|
||
#ifdef interrupts | ||
#undef interrupts | ||
#endif | ||
#ifdef noInterrupts | ||
#undef noInterrupts | ||
#endif | ||
#define noInterrupts() {portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;portENTER_CRITICAL(&mux) | ||
#define interrupts() portEXIT_CRITICAL(&mux);} | ||
|
||
#endif |
Oops, something went wrong.