Skip to content

AVRISP: allow configuring active-high/low reset programatically #736

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

Merged
merged 1 commit into from
Sep 1, 2015
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ extern "C" {
#define malloc os_malloc
#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(...)

Expand All @@ -47,8 +38,8 @@ extern "C" {

#define beget16(addr) (*addr * 256 + *(addr+1))

ESP8266AVRISP::ESP8266AVRISP(uint16_t port, uint8_t reset_pin, uint32_t spi_freq, bool reset_state):
_reset_pin(reset_pin), _reset_state(reset_state), _spi_freq(spi_freq),
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_activehigh(reset_activehigh),
_server(WiFiServer(port)), _state(AVRISP_STATE_IDLE)
{
pinMode(_reset_pin, OUTPUT);
Expand All @@ -68,11 +59,7 @@ void ESP8266AVRISP::setSpiFrequency(uint32_t freq) {

void ESP8266AVRISP::setReset(bool rst) {
_reset_state = rst;
if (_reset_state) {
digitalWrite(_reset_pin, AVRISP_RESET_ON);
} else {
digitalWrite(_reset_pin, AVRISP_RESET_OFF);
}
digitalWrite(_reset_pin, _resetLevel(_reset_state));
}

AVRISPState_t ESP8266AVRISP::update() {
Expand Down Expand Up @@ -230,9 +217,9 @@ void ESP8266AVRISP::start_pmode() {

// try to sync the bus
SPI.transfer(0x00);
digitalWrite(_reset_pin, AVRISP_RESET_OFF);
digitalWrite(_reset_pin, _resetLevel(false));
delayMicroseconds(50);
digitalWrite(_reset_pin, AVRISP_RESET_ON);
digitalWrite(_reset_pin, _resetLevel(true));
delay(30);

spi_transaction(0xAC, 0x53, 0x00, 0x00);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ typedef struct {

class ESP8266AVRISP {
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();

Expand Down Expand Up @@ -100,14 +100,15 @@ class ESP8266AVRISP {
void start_pmode(void); // enter program mode
void end_pmode(void); // exit program mode


inline bool _resetLevel(bool reset_state) { return reset_state == _reset_activehigh; }

uint32_t _spi_freq;
WiFiServer _server;
WiFiClient _client;
AVRISPState_t _state;
uint8_t _reset_pin;
bool _reset_state;
bool _reset_activehigh;

// programmer settings, set by remote end
AVRISP_parameter_t param;
Expand Down