mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
AVRISP: allow configuring active-high/low reset programatically
This commit is contained in:
parent
2a2ecf8d94
commit
cbbb379941
@ -26,15 +26,6 @@ extern "C" {
|
|||||||
#define malloc os_malloc
|
#define malloc os_malloc
|
||||||
#define free os_free
|
#define free os_free
|
||||||
|
|
||||||
#ifdef AVRISP_ACTIVE_HIGH_RESET
|
|
||||||
#define AVRISP_RESET_ON HIGH
|
|
||||||
#define AVRISP_RESET_OFF LOW
|
|
||||||
#else
|
|
||||||
#define AVRISP_RESET_ON LOW
|
|
||||||
#define AVRISP_RESET_OFF HIGH
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// #define AVRISP_DEBUG(fmt, ...) os_printf("[AVRP] " fmt "\r\n", ##__VA_ARGS__ )
|
// #define AVRISP_DEBUG(fmt, ...) os_printf("[AVRP] " fmt "\r\n", ##__VA_ARGS__ )
|
||||||
#define AVRISP_DEBUG(...)
|
#define AVRISP_DEBUG(...)
|
||||||
|
|
||||||
@ -47,8 +38,8 @@ extern "C" {
|
|||||||
|
|
||||||
#define beget16(addr) (*addr * 256 + *(addr+1))
|
#define beget16(addr) (*addr * 256 + *(addr+1))
|
||||||
|
|
||||||
ESP8266AVRISP::ESP8266AVRISP(uint16_t port, uint8_t reset_pin, uint32_t spi_freq, bool reset_state):
|
ESP8266AVRISP::ESP8266AVRISP(uint16_t port, uint8_t reset_pin, uint32_t spi_freq, bool reset_state, bool reset_activehigh):
|
||||||
_reset_pin(reset_pin), _reset_state(reset_state), _spi_freq(spi_freq),
|
_reset_pin(reset_pin), _reset_state(reset_state), _spi_freq(spi_freq), _reset_activehigh(reset_activehigh),
|
||||||
_server(WiFiServer(port)), _state(AVRISP_STATE_IDLE)
|
_server(WiFiServer(port)), _state(AVRISP_STATE_IDLE)
|
||||||
{
|
{
|
||||||
pinMode(_reset_pin, OUTPUT);
|
pinMode(_reset_pin, OUTPUT);
|
||||||
@ -68,11 +59,7 @@ void ESP8266AVRISP::setSpiFrequency(uint32_t freq) {
|
|||||||
|
|
||||||
void ESP8266AVRISP::setReset(bool rst) {
|
void ESP8266AVRISP::setReset(bool rst) {
|
||||||
_reset_state = rst;
|
_reset_state = rst;
|
||||||
if (_reset_state) {
|
digitalWrite(_reset_pin, _resetLevel(_reset_state));
|
||||||
digitalWrite(_reset_pin, AVRISP_RESET_ON);
|
|
||||||
} else {
|
|
||||||
digitalWrite(_reset_pin, AVRISP_RESET_OFF);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AVRISPState_t ESP8266AVRISP::update() {
|
AVRISPState_t ESP8266AVRISP::update() {
|
||||||
@ -230,9 +217,9 @@ void ESP8266AVRISP::start_pmode() {
|
|||||||
|
|
||||||
// try to sync the bus
|
// try to sync the bus
|
||||||
SPI.transfer(0x00);
|
SPI.transfer(0x00);
|
||||||
digitalWrite(_reset_pin, AVRISP_RESET_OFF);
|
digitalWrite(_reset_pin, _resetLevel(false));
|
||||||
delayMicroseconds(50);
|
delayMicroseconds(50);
|
||||||
digitalWrite(_reset_pin, AVRISP_RESET_ON);
|
digitalWrite(_reset_pin, _resetLevel(true));
|
||||||
delay(30);
|
delay(30);
|
||||||
|
|
||||||
spi_transaction(0xAC, 0x53, 0x00, 0x00);
|
spi_transaction(0xAC, 0x53, 0x00, 0x00);
|
||||||
|
@ -47,7 +47,7 @@ typedef struct {
|
|||||||
|
|
||||||
class ESP8266AVRISP {
|
class ESP8266AVRISP {
|
||||||
public:
|
public:
|
||||||
ESP8266AVRISP(uint16_t port, uint8_t reset_pin, uint32_t spi_freq=AVRISP_SPI_FREQ, bool reset_state=false);
|
ESP8266AVRISP(uint16_t port, uint8_t reset_pin, uint32_t spi_freq=AVRISP_SPI_FREQ, bool reset_state=false, bool reset_activehigh=false);
|
||||||
|
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ protected:
|
|||||||
void start_pmode(void); // enter program mode
|
void start_pmode(void); // enter program mode
|
||||||
void end_pmode(void); // exit program mode
|
void end_pmode(void); // exit program mode
|
||||||
|
|
||||||
|
inline bool _resetLevel(bool reset_state) { return reset_state == _reset_activehigh; }
|
||||||
|
|
||||||
uint32_t _spi_freq;
|
uint32_t _spi_freq;
|
||||||
WiFiServer _server;
|
WiFiServer _server;
|
||||||
@ -108,6 +108,7 @@ protected:
|
|||||||
AVRISPState_t _state;
|
AVRISPState_t _state;
|
||||||
uint8_t _reset_pin;
|
uint8_t _reset_pin;
|
||||||
bool _reset_state;
|
bool _reset_state;
|
||||||
|
bool _reset_activehigh;
|
||||||
|
|
||||||
// programmer settings, set by remote end
|
// programmer settings, set by remote end
|
||||||
AVRISP_parameter_t param;
|
AVRISP_parameter_t param;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user