Commit 3e4f3f2b authored by ryukoposting's avatar ryukoposting

added analog write

parent b8cf17c8
......@@ -190,6 +190,13 @@ enum PCGPIO_Status PCGPIO_ProcessMethod(struct PCGPIO_Method *method) {
}
}
break;
case PCGPIO_METHODTYPE_WRITEANALOG:
if(method->method.analog_write.pin == 66) {
analogWrite(DAC0, (method->method.analog_write.value) >> 16);
} else if (method->method.analog_write.pin == 67) {
analogWrite(DAC1, (method->method.analog_write.value) >> 16);
}
break;
case PCGPIO_METHODTYPE_READDIGITAL:
if(method->method.read_digital.pin < 54) {
callback.callback_type = PCGPIO_CALLBACKTYPE_READDIGITAL;
......
......@@ -80,6 +80,32 @@ enum PCGPIO_Status PCGPIO_ProcessNextByte(uint8_t in) {
checksum += in;
next_state = 0x100;
break;
case 0x105: // first data byte of WriteAnalog method
receiver_method.method.write_analog.pin = in;
checksum += in;
next_state = 0x205;
break;
case 0x205:
receiver_method.method.write_analog.value = (in << 24);
checksum += in;
next_state = 0x305;
break;
case 0x305:
receiver_method.method.write_analog.value |= (in << 16);
checksum += in;
next_state = 0x405;
break;
case 0x405:
receiver_method.method.write_analog.value |= (in << 8);
checksum += in;
next_state = 0x505;
break;
case 0x505:
receiver_method.method.write_analog.value |= in;
checksum += in;
next_state = 0x100;
break;
case 0x111: // first data byte of GetPinConfig method
receiver_method.method.read_analog.pin = in;
......
......@@ -20,7 +20,8 @@ code description Callback? Datas Data size(B) Data description
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)
0x05 Write DAC out n Pin 1 The pin to write
Value 4 The value to write
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.
......
......@@ -54,6 +54,18 @@ enum PCGPIO_Status PCGPIO_WriteDigital(struct PCGPIO_Properties *const propertie
return PCGPIO_TransmitMethod(properties, &method);
}
enum PCGPIO_Status PCGPIO_WriteAnalog(struct PCGPIO_Properties *const properties, uint8_t pin, uint32_t value) {
struct PCGPIO_METHOD_WriteAnalog write_analog = {
.pin = pin,
.value = value
};
struct PCGPIO_Method method = {
.method_type = PCGPIO_METHODTYPE_WRITEANALOG
};
method.method.write_analog = write_analog;
return PCGPIO_TransmitMethod(properties, &method);
}
enum PCGPIO_Status PCGPIO_ReadDigital(struct PCGPIO_Properties *const properties, uint8_t pin) {
struct PCGPIO_METHOD_ReadDigital read_digital = {
.pin = pin
......
......@@ -269,7 +269,7 @@ enum PCGPIO_Status PCGPIO_Init(struct PCGPIO_Properties *const properties, char
if(res) return PCGPIO_STATUS_THREAD_ERROR;
}
// TODO get MCU identifier
PCGPIO_RequestMCUID(properties);
return PCGPIO_STATUS_OK;
......@@ -280,7 +280,7 @@ enum PCGPIO_Status PCGPIO_TransmitMethod(struct PCGPIO_Properties *const propert
if(method == NULL) return PCGPIO_STATUS_NULL_PTR;
if(properties->running != 1) return PCGPIO_STATUS_INVALID_PROPERTY;
unsigned char packet_bytes[8] = {0xA5, };
unsigned char packet_bytes[12] = {0xA5, };
// the total length of the packet, including start, checksum and terminator
unsigned int packet_length;
......@@ -309,6 +309,17 @@ enum PCGPIO_Status PCGPIO_TransmitMethod(struct PCGPIO_Properties *const propert
packet_bytes[5] = PCGPIO_MakeMethodChecksum(packet_bytes, packet_length);
packet_bytes[6] = 0x0A;
break;
case PCGPIO_METHODTYPE_WRITEANALOG:
packet_length = 9;
packet_bytes[1] = (unsigned char)(method->method_type);
packet_bytes[2] = method->method.write_analog.pin;
packet_bytes[3] = (uint8_t)(((method->method.write_analog.value) & 0xFF000000) >> 24);
packet_bytes[4] = (uint8_t)(((method->method.write_analog.value) & 0x00FF0000) >> 16);
packet_bytes[5] = (uint8_t)(((method->method.write_analog.value) & 0x0000FF00) >> 8);
packet_bytes[6] = (uint8_t)( (method->method.write_analog.value) & 0x000000FF);
packet_bytes[7] = PCGPIO_MakeMethodChecksum(packet_bytes, packet_length);
packet_bytes[8] = 0x0A;
break;
case PCGPIO_METHODTYPE_READDIGITAL:
packet_length = 5;
packet_bytes[1] = (unsigned char)(method->method_type);
......
......@@ -63,6 +63,8 @@ enum PCGPIO_Status PCGPIO_IOConfig(struct PCGPIO_Properties *const properties, u
enum PCGPIO_Status PCGPIO_WriteDigital(struct PCGPIO_Properties *const properties, uint8_t pin, uint16_t value);
enum PCGPIO_Status PCGPIO_WriteAnalog(struct PCGPIO_Properties *const properties, uint8_t pin, uint32_t value);
enum PCGPIO_Status PCGPIO_ReadDigital(struct PCGPIO_Properties *const properties, uint8_t pin);
enum PCGPIO_Status PCGPIO_ReadAnalog(struct PCGPIO_Properties *const properties, uint8_t pin);
......
......@@ -29,6 +29,7 @@ enum PCGPIO_MethodType {
PCGPIO_METHODTYPE_WRITEDIGITAL = 0x02U,
PCGPIO_METHODTYPE_READDIGITAL = 0x03U,
PCGPIO_METHODTYPE_READANALOG = 0x04U,
PCGPIO_METHODTYPE_WRITEANALOG = 0x05U,
PCGPIO_METHODTYPE_GETPINCONFIG = 0x11U
};
......@@ -47,6 +48,11 @@ struct PCGPIO_METHOD_WriteDigital {
uint16_t value;
};
struct PCGPIO_METHOD_WriteAnalog {
uint8_t pin;
uint32_t value;
};
struct PCGPIO_METHOD_ReadDigital {
uint8_t pin;
};
......@@ -55,11 +61,6 @@ struct PCGPIO_METHOD_ReadAnalog {
uint8_t pin;
};
// struct PCGPIO_METHOD_WriteAnalog {
// unsigned char pin;
// unsigned int value;
// };
struct PCGPIO_METHOD_GetPinConfig {
uint8_t pin;
};
......@@ -70,6 +71,7 @@ struct PCGPIO_Method {
struct PCGPIO_METHOD_MCUIdentity mcu_identity;
struct PCGPIO_METHOD_IOPinConfig io_pin_config;
struct PCGPIO_METHOD_WriteDigital write_digital;
struct PCGPIO_METHOD_WriteAnalog write_analog;
struct PCGPIO_METHOD_ReadDigital read_digital;
struct PCGPIO_METHOD_ReadAnalog read_analog;
struct PCGPIO_METHOD_GetPinConfig get_pin_config;
......
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