Commit b741eb6e authored by ryukoposting's avatar ryukoposting

tweaks to mcu-side state machine

parent 62945d57
......@@ -16,6 +16,7 @@ enum PCGPIO_Status PCGPIO_SendMCUID() {
}
enum PCGPIO_Status PCGPIO_ProcessNextByte(uint8_t in) {
enum PCGPIO_Status retval = PCGPIO_STATUS_OK;
switch(state) {
case 0: // no message currently in transmission
if(in == 0xA5) {
......@@ -25,22 +26,22 @@ enum PCGPIO_Status PCGPIO_ProcessNextByte(uint8_t in) {
next_state = 0;
}
break;
case 1: // got a start byte. figure out what method it is
receiver_method.method_type = (enum PCGPIO_MethodType)in;
next_state = 0x100 + in;
checksum += in;
break;
case 0x100: // checksum byte
if(checksum == (in & 0xFF)) {
next_state = 0xFFFF;
} else {
state = 0x7FFF;
return PCGPIO_STATUS_INCORRECT_CHECKSUM;
next_state = 0x7FFF;
retval = PCGPIO_STATUS_INCORRECT_CHECKSUM;
}
break;
case 0x101: // first data byte of IOPinConfig method
receiver_method.method.io_pin_config.pin = in;
checksum += in;
......@@ -51,7 +52,7 @@ enum PCGPIO_Status PCGPIO_ProcessNextByte(uint8_t in) {
checksum += in;
next_state = 0x100;
break;
case 0x102: // first data byte of WriteDigital method
receiver_method.method.write_digital.pin = in;
checksum += in;
......@@ -67,52 +68,54 @@ enum PCGPIO_Status PCGPIO_ProcessNextByte(uint8_t in) {
checksum += in;
next_state = 0x100;
break;
case 0x103: // first data byte of ReadDigital method
receiver_method.method.read_digital.pin = in;
checksum += in;
next_state = 0x100;
break;
case 0x104: // first data byte of ReadAnalog method
receiver_method.method.read_analog.pin = in;
checksum += in;
next_state = 0x100;
break;
case 0x111: // first data byte of GetPinConfig method
receiver_method.method.read_analog.pin = in;
checksum += in;
next_state = 0x100;
break;
case 0x7FFF: // error recovery state
if(in == 0x0A) {
next_state = 0;
} else if(in == 0xA5) {
next_state = 1;
} else {
return PCGPIO_STATUS_IN_RECOVERY_STATE;
// state stays the same
retval = PCGPIO_STATUS_IN_RECOVERY_STATE;
}
break;
case 0xFFFF: // should get stop byte
if(in == 0x0A) {
// we have gotten a complete, properly formatted method!
state = 0;
return PCGPIO_ProcessMethod(&receiver_method);
} else {
state = 0x7FFF;
return PCGPIO_STATUS_INCORRECT_STOPBYTE;
next_state = 0x7FFF;
retval = PCGPIO_STATUS_INCORRECT_STOPBYTE;
}
break;
default:
state = 0x7FFF;
next_state = 0x7FFF;
retval = PCGPIO_STATUS_INTERNAL_FAILURE;
}
state = next_state;
return PCGPIO_STATUS_OK;
return retval;
}
enum PCGPIO_Status PCGPIO_SendDigitalInputRead(uint8_t pin, uint8_t value) {
......@@ -150,4 +153,3 @@ enum PCGPIO_Status PCGPIO_SendPinConfig(uint8_t pin, uint8_t conf) {
callback.callback.get_pin_config = get_pin_config;
return PCGPIO_TransmitCallback(&callback);
}
// PC-GPIO
// Copyright (C) 2018 ryukoposting
//
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//
// Contact:
// email: epg@tfwno.gf
......@@ -25,7 +25,7 @@
#ifdef __cplusplus
extern "C" {
#endif
uint8_t pin_modes[PCGPIO_PIN_COUNT] = {};
uint8_t pin_last_scan[PCGPIO_PIN_COUNT] = {};
......@@ -52,6 +52,7 @@ enum PCGPIO_Status PCGPIO_SendPinConfig(uint8_t pin, uint8_t conf);
}
#endif
// HACK HACK HACK HACK HACK FOR THE LOVE OF GOD FIGURE OUT ANOTHER WAY
#ifdef PCGPIO_TARGET_ARCHITECTURE_ARDUINO_DUE
#include "pcgpio_mcu-common.c"
#include "arduino/pcgpio_mcu-due.c"
......
// PC-GPIO
// Copyright (C) 2018 ryukoposting
//
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//
// Contact:
// email: epg@tfwno.gf
......@@ -40,7 +40,8 @@ enum PCGPIO_Status {
PCGPIO_STATUS_POLLING_ERROR = 8U,
PCGPIO_STATUS_INCORRECT_CHECKSUM = 9U,
PCGPIO_STATUS_INCORRECT_STOPBYTE = 10U,
PCGPIO_STATUS_IN_RECOVERY_STATE = 11U
PCGPIO_STATUS_IN_RECOVERY_STATE = 11U,
PCGPIO_STATUS_INTERNAL_FAILURE = 12U
};
enum PCGPIO_PinConfig {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment