Commit 6e5fa601 authored by ryukoposting's avatar ryukoposting

digital read/write, PWM, analog read

parent b104a546
......@@ -8,3 +8,8 @@ Code Manufacturer Part number(s)
0x0302 Arduino Mega2560
0x0303 Arduino Mega ADK
0x0400 Infineon XMC1400
considering supporting:
Zilog Z8
8051
......@@ -112,7 +112,6 @@ enum PCGPIO_Status PCGPIO_TransmitCallback(struct PCGPIO_Callback *callback) {
break;
case PCGPIO_CALLBACKTYPE_READANALOG:
length = 9;
//TODO: logic for resolution bitshifts should go here
buffer[2] = callback->callback.read_analog.pin;
buffer[3] = ((callback->callback.read_analog.value >> 24) & 0xFF);
buffer[4] = ((callback->callback.read_analog.value >> 16) & 0xFF);
......@@ -191,9 +190,27 @@ enum PCGPIO_Status PCGPIO_ProcessMethod(struct PCGPIO_Method *method) {
}
}
break;
case PCGPIO_METHODTYPE_READDIGITAL:
case PCGPIO_METHODTYPE_READDIGITAL:
if(method->method.read_digital.pin < 54) {
callback.callback_type = PCGPIO_CALLBACKTYPE_READDIGITAL;
struct PCGPIO_CALLBACK_ReadDigital read_digital = {
.pin = (method->method.read_digital.pin),
.value = digitalRead(method->method.read_digital.pin)
};
callback.callback.read_digital = read_digital;
PCGPIO_TransmitCallback(&callback);
}
break;
case PCGPIO_METHODTYPE_READANALOG:
if((method->method.read_digital.pin >= 54) && (method->method.read_digital.pin < 66)) {
callback.callback_type = PCGPIO_CALLBACKTYPE_READANALOG;
struct PCGPIO_CALLBACK_ReadAnalog read_analog = {
.pin = (method->method.read_digital.pin),
.value = analogRead(method->method.read_digital.pin)
};
callback.callback.read_analog = read_analog;
PCGPIO_TransmitCallback(&callback);
}
break;
case PCGPIO_METHODTYPE_GETPINCONFIG:
break;
......
......@@ -63,7 +63,7 @@ enum PCGPIO_Status PCGPIO_ProcessNextByte(uint8_t in) {
checksum += in;
next_state = 0x302;
break;
case 0x301: // third data byte of WriteDigital method
case 0x302: // third data byte of WriteDigital method
receiver_method.method.write_digital.value |= (in & 0x00FF);
checksum += in;
next_state = 0x100;
......
......@@ -12,16 +12,24 @@ A "method" is a packet going PC->MCU
A "callback" is a packet going MCU->PC
Methods
code description Callback? Datas Data size(B) Data description
0x00 Get MCU ID y none
0x01 IO pin config n Pin 1 The pin to configure
Conf 1 The pin's configuration
0x02 Write output n Pin 1 The pin to write
Value 2 0 = off, anything else = on, sets duty cycle for PWM
0x03 Read dig input y Pin 1 The pin to read
0x04 Read analog in y Pin 1 The pin to read
0x05 Write DAC out n (NYI)
0x11 Get pin config y Pin 1 The pin for which to get the configuration
code description Callback? Datas Data size(B) Data description
0x00 Get MCU ID y none
0x01 IO pin config n Pin 1 The pin to configure
Conf 1 The pin's configuration
0x02 Write output n Pin 1 The pin to write
Value 2 0 = off, anything else = on, sets duty cycle for PWM
0x03 Read dig input y Pin 1 The pin to read
0x04 Read analog in y Pin 1 The pin to read
0x05 Write DAC out n (NYI)
0x11 Get pin config y Pin 1 The pin for which to get the configuration
0xF8 Special function 0 ? (4 bytes total) MCU-specific.
0xF9 Special function 1 ? (4 bytes total) MCU-specific.
0xFA Special function 2 ? (4 bytes total) MCU-specific.
0xFB Special function 3 ? (4 bytes total) MCU-specific.
0xFC Special function 4 ? (4 bytes total) MCU-specific.
0xFD Special function 5 ? (4 bytes total) MCU-specific.
0xFE Special function 6 ? (4 bytes total) MCU-specific.
0xFF Special function 7 ? (4 bytes total) MCU-specific.
Method Datas:
0x01.PIN: see device-spicific pin table.
......
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