diff options
author | Mihai Serban <mihai.serban@intel.com> | 2016-07-01 14:55:25 +0300 |
---|---|---|
committer | Mihai Serban <mihai.serban@intel.com> | 2016-07-04 15:49:56 +0300 |
commit | b33fe8d1c1c2ce22c58b02160eeda61b80eb1d26 (patch) | |
tree | efa2da1c44a8ebe8a3425291bd4f54c7fac299e8 /peripheral/libmraa/include/firmata | |
parent | 180fd6f2baf51cc437c8ba84b053b2b9ed2cca11 (diff) | |
download | intel-b33fe8d1c1c2ce22c58b02160eeda61b80eb1d26.tar.gz |
libmraa: sync with upstream (SHA1: d336e9f)
URL: https://github.com/intel-iot-devkit/mraa
Branch: master
SHA1: d336e9f8d69a85b6ed1aeb5b324910234031d4a8
BUG=None
Change-Id: I0f49f13c5deccd1a42936b5934b6baf74eb8d03b
Signed-off-by: Mihai Serban <mihai.serban@intel.com>
Diffstat (limited to 'peripheral/libmraa/include/firmata')
-rw-r--r-- | peripheral/libmraa/include/firmata/firmata.h | 114 | ||||
-rw-r--r-- | peripheral/libmraa/include/firmata/firmata_mraa.h | 38 |
2 files changed, 152 insertions, 0 deletions
diff --git a/peripheral/libmraa/include/firmata/firmata.h b/peripheral/libmraa/include/firmata/firmata.h new file mode 100644 index 0000000..72961cb --- /dev/null +++ b/peripheral/libmraa/include/firmata/firmata.h @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2016 Intel Corporation + * Copyright (c) 2015 Jules Dourlens (jdourlens@gmail.com) + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +#include "uart.h" + +#define MODE_INPUT 0x00 +#define MODE_OUTPUT 0x01 +#define MODE_ANALOG 0x02 +#define MODE_PWM 0x03 +#define MODE_SERVO 0x04 +#define MODE_SHIFT 0x05 +#define MODE_I2C 0x06 + +#define LOW 0 +#define HIGH 1 + +#define FIRMATA_START_SYSEX 0xF0 // start a MIDI Sysex message +#define FIRMATA_END_SYSEX 0xF7 // end a MIDI Sysex message +#define FIRMATA_PIN_MODE_QUERY 0x72 // ask for current and supported pin modes +#define FIRMATA_PIN_MODE_RESPONSE 0x73 // reply with current and supported pin modes +#define FIRMATA_PIN_STATE_QUERY 0x6D +#define FIRMATA_PIN_STATE_RESPONSE 0x6E +#define FIRMATA_CAPABILITY_QUERY 0x6B +#define FIRMATA_CAPABILITY_RESPONSE 0x6C +#define FIRMATA_ANALOG_MAPPING_QUERY 0x69 +#define FIRMATA_ANALOG_MAPPING_RESPONSE 0x6A + +#define FIRMATA_DIGITAL_MESSAGE 0x90 // send data for a digital pin +#define FIRMATA_ANALOG_MESSAGE 0xE0 // send data for an analog pin (or PWM) +#define FIRMATA_ANALOG_MESSAGE 0xE0 // send data for an analog pin (or PWM) +#define FIRMATA_REPORT_ANALOG 0xC0 // enable analog input by pin # +#define FIRMATA_REPORT_DIGITAL 0xD0 // enable digital input by port pair + +#define FIRMATA_I2C_CONFIG 0x78 +#define FIRMATA_I2C_REPLY 0x77 +#define FIRMATA_I2C_REQUEST 0x76 + +#define I2C_MODE_WRITE 0x00 +#define I2C_MODE_READ 0x01 +#define I2C_CONTINUOUSREAD 0x02 +#define I2C_STOP_READING 0x03 + +#define FIRMATA_SET_PIN_MODE 0xF4 // set a pin to INPUT/OUTPUT/PWM/etc + +#define FIRMATA_REPORT_VERSION 0xF9 // report protocol version +#define FIRMATA_SYSTEM_RESET 0xFF // reset from MIDI + +#define FIRMATA_START_SYSEX 0xF0 // start a MIDI Sysex message +#define FIRMATA_END_SYSEX 0xF7 // end a MIDI Sysex message + +// extended command set using sysex (0-127/0x00-0x7F) +/* 0x00-0x0F reserved for custom commands */ +#define FIRMATA_SERVO_CONFIG 0x70 // set max angle, minPulse, maxPulse, freq +#define FIRMATA_STRING 0x71 // a string message with 14-bits per char +#define FIRMATA_REPORT_FIRMWARE 0x79 // report name and version of the firmware +#define FIRMATA_SYSEX_NON_REALTIME 0x7E // MIDI Reserved for non-realtime messages +#define FIRMATA_SYSEX_REALTIME 0x7F // MIDI Reserved for realtime messages + +#define FIRMATA_MSG_LEN 1024 + +typedef struct s_pin { + uint8_t mode; + uint8_t analog_channel; + uint64_t supported_modes; + uint32_t value; +} t_pin; + +typedef struct s_firmata { + mraa_uart_context uart; + t_pin pins[128]; + int i2cmsg[256][256]; + int parse_command_len; + int parse_count; + uint8_t parse_buff[FIRMATA_MSG_LEN]; + int isReady; + char firmware[140]; + uint8_t dev_count; + struct _firmata** devs; +} t_firmata; + +t_firmata* firmata_new(const char* name); +void firmata_initPins(t_firmata* firmata); +int firmata_askFirmware(t_firmata* firmata); +int firmata_pinMode(t_firmata* firmata, int pin, int mode); +int firmata_digitalWrite(t_firmata* firmata, int pin, int value); +int firmata_analogWrite(t_firmata* firmata, int pin, int value); +int firmata_analogRead(t_firmata* firmata, int pin); +int firmata_pull(t_firmata* firmata); +void firmata_parse(t_firmata* firmata, const uint8_t* buf, int len); +void firmata_endParse(t_firmata* firmata); +void firmata_close(t_firmata* firmata); diff --git a/peripheral/libmraa/include/firmata/firmata_mraa.h b/peripheral/libmraa/include/firmata/firmata_mraa.h new file mode 100644 index 0000000..a80d73a --- /dev/null +++ b/peripheral/libmraa/include/firmata/firmata_mraa.h @@ -0,0 +1,38 @@ +/* + * Author: Brendan Le Foll <brendan.le.foll@intel.com> + * Copyright (c) 2016 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "mraa_internal.h" + +mraa_platform_t mraa_firmata_platform(mraa_board_t* board, const char* uart_dev); + + +#ifdef __cplusplus +} +#endif |