diff --git a/02 Using the I2C Protocol.md b/02 Using the I2C Protocol.md index 38980a8..4435568 100644 --- a/02 Using the I2C Protocol.md +++ b/02 Using the I2C Protocol.md @@ -146,3 +146,12 @@ If we want the script to run automatically we need to add it as a _cron_ task. W This tells the crontab to run the script when the device boots. The `&` character runs the script in the background. Try rebooting the server, you should see the information displayed as soon as the reboot is complete. ## 3 Reading Data from a Sensor + +In this task you will be adding a GY-61 ADXL335 / 345 Module which can be used to measure the angle of the raspberry pi. + +- TC74 temperature sensor +- VEML6070 UV light sensor +- TSL2561 light sensor +- 4 channel ADC +- BMP280 temperature/humidity (also SPI) +- HMC5883L Compass diff --git a/03 Using the SPI Protocol.md b/03 Using the SPI Protocol.md new file mode 100644 index 0000000..b622f88 --- /dev/null +++ b/03 Using the SPI Protocol.md @@ -0,0 +1,12 @@ + +# Using the SPI Protocol + +- Display using the e-ink screen? +- Writing to an SD card? + +Sensors + +- RFID +- ADXL345 3-axis accelerometer tilt sensor (also I2C) +- BMP280 temperature/humidity (also I2C) +- CD74HC4067 CMOS 16 Channel Digital Analog Multiplexer diff --git a/03 Creating an MQTT Broker.md b/05 Creating an MQTT Broker.md similarity index 100% rename from 03 Creating an MQTT Broker.md rename to 05 Creating an MQTT Broker.md diff --git a/exercises/01_arduino/power/ac_current.cpp b/exercises/01_arduino/power/ac_current.cpp deleted file mode 100644 index bf4fd13..0000000 --- a/exercises/01_arduino/power/ac_current.cpp +++ /dev/null @@ -1,49 +0,0 @@ - -const unsigned int numReadings = 200; //samples to calculate Vrms. - -int readingsVClamp[numReadings]; // samples of the sensor SCT-013-000 -int readingsGND[numReadings]; // samples of the virtual ground -float SumSqGND = 0; -float SumSqVClamp = 0; -float total = 0; - - -int PinVClamp = A0; // Sensor SCT-013-000 -int PinVirtGND = A1; // Virtual ground - -void setup() { - Serial.begin(9600); - // initialize all the readings to 0: - for (int thisReading = 0; thisReading < numReadings; thisReading++) { - readingsVClamp[thisReading] = 0; - readingsGND[thisReading] = 0; - } -} - -void loop() { - unsigned int i=0; - SumSqGND = 0; - SumSqVClamp = 0; - total = 0; - - for (unsigned int i=0; i - - - - - Simple MQTT Client - - - - - - - -

Simple MQTT Client

-
- - - diff --git a/exercises/02_mqtt/web/chat/module.js b/exercises/02_mqtt/web/chat/module.js deleted file mode 100644 index 947f4c7..0000000 --- a/exercises/02_mqtt/web/chat/module.js +++ /dev/null @@ -1,33 +0,0 @@ - -'use strict' - -/* eslint no-unused-vars: 0 */ - -const messages = ( function() { - let msgs = [] - return { - extractData: payloadString => { - return payloadString - }, - add: data => { - if(data === '') throw new Error('empty string parameter') - msgs[0] = data - }, - get html() { - let html = '' - for(const msg of msgs) { - html += `

${msg}

` - } - return html - }, - get all() { - return msgs - }, - get count() { - return msgs.length - }, - clear: () => { - msgs = [] - } - } -})() diff --git a/exercises/02_mqtt/web/chat/mqtt.js b/exercises/02_mqtt/web/chat/mqtt.js deleted file mode 100644 index da41ebf..0000000 --- a/exercises/02_mqtt/web/chat/mqtt.js +++ /dev/null @@ -1,55 +0,0 @@ - -'use strict' - -/* eslint no-undef: 0, no-magic-numbers: 0 */ - -const client = new Messaging.Client('broker.mqttdashboard.com', 8000, `myclientid_${parseInt(Math.random() * 100, 10)}`) - -client.onConnectionLost = responseObject => console.log(`connection lost: ${responseObject.errorMessage}`) -client.onMessageArrived = message => { - console.log(message) - console.log(`Topic: ${message.destinationName} Payload: ${message.payloadString}`) - try { - const msg = messages.extractData(message.payloadString) - messages.add(msg) - document.querySelector('div').innerHTML = messages.html - } catch(err) { - console.log(err.message) - } -} - -const publish = (payload, topic, qos) => { - const message = new Messaging.Message(payload) - message.destinationName = topic - message.qos = qos - client.send(message) -} - -const options = { - timeout: 3, - onSuccess: () => { - console.log('connected') - client.subscribe('cu/#', {qos: 2}) - console.log('Subscribed') - }, - onFailure: message => console.log(`Connection failed: ${message.errorMessage}`) -} - -client.connect({ - onSuccess: onConnect, - userName: 'Username', - password: 'password' -}) - -document.addEventListener('DOMContentLoaded', () => { - console.log('page loaded') - document.querySelector('input').onkeyup = e => { - console.log('keyup') - if(e.which === 13) { - console.log('enter key pressed') - const payload = document.querySelector('input').value - publish(payload,'cu/chat',2) - document.querySelector('input').value = '' - } - } -}) diff --git a/exercises/02_mqtt/web/chat/test/module.test.js b/exercises/02_mqtt/web/chat/test/module.test.js deleted file mode 100644 index 419a72e..0000000 --- a/exercises/02_mqtt/web/chat/test/module.test.js +++ /dev/null @@ -1,134 +0,0 @@ - -'use strict' - -/* eslint no-undef: 0 */ - -describe('check encapsulation', () => { - it('check message array is private', () => { - try { - const data = msgs - expect(1).toBe(0) // this line should not be run! - console.log(data) - } catch(err) { - expect(err.message).toBe('Can\'t find variable: msgs') - } - }) -}) - -describe('properties', () => { - - describe('html', () => { - - beforeEach( () => messages.clear()) - - it('when adding a single message', () => { - messages.add('hello world') - const html = messages.html - expect(html).toBe('

hello world

') - }) - - it('when adding multiple messages', () => { - messages.add('hello') - messages.add('goodbye') - const html = messages.html - expect(html).toBe('

goodbye

') - }) - - }) - - describe('all', () => { - - beforeEach( () => messages.clear()) - - it('when adding a single message', () => { - messages.add('hello world') - const msgs = messages.all - expect(Array.isArray(msgs)).toBeTruthy() - expect(msgs.length).toBe(1) - }) - - it('when adding multiple messages', () => { - messages.add('hello') - messages.add('goodbye') - const msgs = messages.all - expect(Array.isArray(msgs)).toBeTruthy() - expect(msgs.length).toBe(1) - }) - - }) - - describe('count', () => { - - it('when adding a single message', () => { - messages.add('hello world') - expect(messages.count).toBe(1) - }) - - it('when adding multiple messages', () => { - messages.add('hello') - messages.add('goodbye') - expect(messages.count).toBe(1) - }) - - }) - -}) - -describe('methods', () => { - describe('extractData', () => { - - it('returns the message', () => { - const msg = messages.extractData('Hello World') - expect(msg).toBe('Hello World') - }) - - }) - - describe('addMessage', () => { - - beforeEach( () => messages.clear()) - - it('add a single message', () => { - messages.add('hello world') - expect(messages.count).toBe(1) - const msgs = messages.all - expect(msgs[0]).toBe('hello world') - }) - - it('adding multiple messages', () => { - messages.add('hello') - messages.add('goodbye') - expect(messages.count).toBe(1) - const msgs = messages.all - expect(msgs[0]).toBe('goodbye') - }) - - it('adding an empty message should throw an error', () => { - try { - messages.add('') - expect(1).toBe(0) // this line should not be run! - } catch(err) { - expect(err.message).toBe('empty string parameter') - } - }) - - }) - - describe('clear', () => { - - it('clearing a single message', () => { - messages.add('hello world') - messages.clear() - expect(messages.count).toBe(0) - }) - - it('clearing multiple messages', () => { - messages.add('hello') - messages.add('goodbye') - messages.clear() - expect(messages.count).toBe(0) - }) - - }) - -}) diff --git a/exercises/02_mqtt/web/chat/test/testrunner.html b/exercises/02_mqtt/web/chat/test/testrunner.html deleted file mode 100644 index 02d8362..0000000 --- a/exercises/02_mqtt/web/chat/test/testrunner.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - Running Jasmine tests in the browser - - - - - - - - - - - - - diff --git a/exercises/02_mqtt/web/maps/index.html b/exercises/02_mqtt/web/maps/index.html deleted file mode 100644 index e6fac7a..0000000 --- a/exercises/02_mqtt/web/maps/index.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - -
- - - diff --git a/exercises/02_mqtt/web/maps/map.js b/exercises/02_mqtt/web/maps/map.js deleted file mode 100644 index 7bd1c03..0000000 --- a/exercises/02_mqtt/web/maps/map.js +++ /dev/null @@ -1,46 +0,0 @@ - -'use strict' - -let map - -function loadMap() { - const mapOptions = { - center:new google.maps.LatLng(52.4080, -1.5104), - zoom:12, - mapTypeId:google.maps.MapTypeId.ROADMAP - } - map = new google.maps.Map(document.getElementById('sample'),mapOptions) - if (navigator.geolocation) { - navigator.geolocation.getCurrentPosition( position => { - console.log(`current location: ${position.coords.latitude}, ${position.coords.longitude}`) - map.setCenter(new google.maps.LatLng(position.coords.latitude, position.coords.longitude)) - }) - } -} - -google.maps.event.addDomListener(window, 'load', loadMap) - -// ------- MQTT STUFF - -const client = new Messaging.Client('broker.mqttdashboard.com', 8000, `myclientid_${parseInt(Math.random() * 100, 10)}`) - -client.onConnectionLost = responseObject => console.log(`connection lost: ${responseObject.errorMessage}`) - -client.onMessageArrived = message => { - const data = maps.extractData(message.payloadString) - maps.addMarker(data) - maps.scale(map) - //scaleMap() -} - -const options = { - timeout: 3, - onSuccess: () => { - console.log('connected') - client.subscribe('cov/map', {qos: 2}) - console.log('Subscribed') - }, - onFailure: message => console.log(`Connection failed: ${message.errorMessage}`) -} - -client.connect(options) diff --git a/exercises/02_mqtt/web/maps/module.js b/exercises/02_mqtt/web/maps/module.js deleted file mode 100644 index 93c242e..0000000 --- a/exercises/02_mqtt/web/maps/module.js +++ /dev/null @@ -1,46 +0,0 @@ - -'use strict' - -const maps = (function() { - - const markers = [] - - return { - extractData: payloadString => { - try { - const data = JSON.parse(payloadString) - return data - } catch(err) { - if(err.message === 'Unexpected token h in JSON at position 0') { - throw new Error('parameter is not a json string') - } - throw new Error(err) // we need to propagate all other errors - } - }, - addMarker: data => { - const latLng = new google.maps.LatLng(data.lat, data.lon) - const mkr = { position: latLng, title: data.label } - const marker = new google.maps.Marker(mkr) - markers.push(marker) - return marker - }, - get all() { - return markers - }, - scale: map => { - let bounds = new google.maps.LatLngBounds() - const markers = maps.all - for (var i = 0; i < markers.length; i++) { - markers[i].setMap(map) - bounds.extend(markers[i].getPosition()) - } - map.fitBounds(bounds) - console.log(`zoom level: ${map.getZoom()}`) - if(map.getZoom() > 16) map.setZoom(16) - const currentBounds = map.getBounds() - console.log(JSON.stringify(currentBounds, null, 2)) - return currentBounds - } - } - -})() diff --git a/exercises/02_mqtt/web/maps/style.css b/exercises/02_mqtt/web/maps/style.css deleted file mode 100644 index 88cc536..0000000 --- a/exercises/02_mqtt/web/maps/style.css +++ /dev/null @@ -1,5 +0,0 @@ - -#sample { - width:800px; - height:400px; -} \ No newline at end of file diff --git a/exercises/02_mqtt/web/maps/test/module.test.js b/exercises/02_mqtt/web/maps/test/module.test.js deleted file mode 100644 index c95cff0..0000000 --- a/exercises/02_mqtt/web/maps/test/module.test.js +++ /dev/null @@ -1,66 +0,0 @@ - -'use strict' - -/* eslint no-undef: 0 */ - -describe('check encapsulation', () => { - it('check markers array is private', () => { - try { - const data = markers - expect(1).toBe(0) // this line should not be run! - console.log(data) - } catch(err) { - expect(err.message).toBe('markers is not defined') - } - }) - - describe('properties', () => { - - describe('all', () => { - - it('check for an empty array', () => { - const pins = maps.all - console.log(pins) - expect(Array.isArray(pins)).toBeTruthy() - expect(pins.length).toBe(0) - }) - - }) - - }) - - describe('methods', () => { - - describe('extractData', () => { - - it('extracts complete data', () => { - const str = '{"lat": 52.4082, "lon": -1.5071, "label": "cathedral"}' - const data = maps.extractData(str) - expect(typeof data).toBe('object') - expect(Object.keys(data).length).toBe(3) - expect(data.lat).toBe(52.4082) - expect(data.lon).toBe(-1.5071) - expect(data.label).toBe('cathedral') - }) - - it('throw error if parameter is not a json string', () => { - try { - maps.extractData('hello world') - expect(0).toBe(1) - } catch(err) { - expect(err.message).toBe('parameter is not a json string') - } - }) - - }) - - describe('addMarker', () => { - - }) - - describe('scale', () => { - - }) - - }) -}) diff --git a/exercises/02_mqtt/web/maps/test/testrunner.html b/exercises/02_mqtt/web/maps/test/testrunner.html deleted file mode 100644 index 960a908..0000000 --- a/exercises/02_mqtt/web/maps/test/testrunner.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - Running Jasmine tests in the browser - - - - - - - - - - - - - - diff --git a/exercises/02_tdd/temp/lib/avg/avg.cpp b/exercises/02_tdd/temp/lib/avg/avg.cpp deleted file mode 100644 index 8f42f07..0000000 --- a/exercises/02_tdd/temp/lib/avg/avg.cpp +++ /dev/null @@ -1,18 +0,0 @@ - -#include - -int readings[6]; -int index = 0; - -void avg_add(int a) { - readings[index] = a; - index++; -} - -int avg_get() { - return 0; -} - -void avg_clear() { - index = 0; -} diff --git a/exercises/02_tdd/temp/lib/avg/avg.h b/exercises/02_tdd/temp/lib/avg/avg.h deleted file mode 100644 index 1cb0d01..0000000 --- a/exercises/02_tdd/temp/lib/avg/avg.h +++ /dev/null @@ -1,9 +0,0 @@ - -#ifndef __AVG_H -#define __AVG_H - -void avg_add(int a); -int avg_get(); -void avg_clear(); - -#endif diff --git a/exercises/02_tdd/temp/lib/readme.txt b/exercises/02_tdd/temp/lib/readme.txt deleted file mode 100644 index cfa16df..0000000 --- a/exercises/02_tdd/temp/lib/readme.txt +++ /dev/null @@ -1,41 +0,0 @@ - -This directory is intended for project specific (private) libraries. -PlatformIO will compile them to static libraries and link them to executable files. - -The source code of each library should be placed in separate directories, like -"lib/private_lib/[here are source files]". - -For example, see the structure of the following two libraries `Foo` and `Bar`: - -|--lib -| | -| |--Bar -| | |--docs -| | |--examples -| | |--src -| | |- Bar.c -| | |- Bar.h -| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html -| | -| |--Foo -| | |- Foo.c -| | |- Foo.h -| | -| |- readme.txt --> THIS FILE -| -|- platformio.ini -|--src - |- main.c - -Then in `src/main.c` you should use: - -#include -#include - -// rest H/C/CPP code - -PlatformIO will find your libraries automatically, configure preprocessor's -include paths and build them. - -More information about PlatformIO Library Dependency Finder -- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/exercises/02_tdd/temp/platformio.ini b/exercises/02_tdd/temp/platformio.ini deleted file mode 100644 index 64027ca..0000000 --- a/exercises/02_tdd/temp/platformio.ini +++ /dev/null @@ -1,23 +0,0 @@ -; PlatformIO Project Configuration File -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html - -;monitor_speed = 9600 - -[env:nodemcuv2] -platform = espressif8266 -board = nodemcuv2 -framework = arduino -; upload_port = /dev/ttyUSB0 -upload_speed = 57600 ; 9600 14400 19200 28800 38400 57600 115200 - -[env:lolin32] -platform = espressif32 -board = lolin32 -framework = arduino -; upload_port = /dev/ttyUSB0 -upload_speed = 115200 ; 9600 14400 19200 28800 38400 57600 115200 - -[env:native] -platform = native diff --git a/exercises/02_tdd/temp/readme.md b/exercises/02_tdd/temp/readme.md deleted file mode 100644 index b595362..0000000 --- a/exercises/02_tdd/temp/readme.md +++ /dev/null @@ -1,22 +0,0 @@ - -# Notes - -The platformio commands are stored in this directory: - -~/.platformio/penv/bin - -commands: - -Starting a project for the NodeMCU v2 environment: - -platformio init -b nodemcuv2 - -To flash to a device: - -$ pio run -e nodemcuv2 - -HOw to run the tests: - -~/.platformio/penv/bin/pio test -e native - -https://www.thingforward.io/techblog/2017-07-25-starting-embedded-testing-with-platformio.html diff --git a/exercises/02_tdd/temp/src/main.cpp b/exercises/02_tdd/temp/src/main.cpp deleted file mode 100644 index a36d148..0000000 --- a/exercises/02_tdd/temp/src/main.cpp +++ /dev/null @@ -1,24 +0,0 @@ - -#ifndef UNIT_TEST - -#include -#include - -long randNumber; - -void setup() { - Serial.begin(9600); - pinMode(LED_BUILTIN, OUTPUT); - randomSeed(analogRead(0)); -} - -void loop() { - randNumber = random(10, 20); - Serial.println(randNumber); - digitalWrite(LED_BUILTIN, HIGH); - delay(1000); - digitalWrite(LED_BUILTIN, LOW); - delay(1000); -} - -#endif diff --git a/exercises/02_tdd/temp/test/test_desktop/test_avg.cpp b/exercises/02_tdd/temp/test/test_desktop/test_avg.cpp deleted file mode 100644 index e78d58d..0000000 --- a/exercises/02_tdd/temp/test/test_desktop/test_avg.cpp +++ /dev/null @@ -1,20 +0,0 @@ - -#ifdef UNIT_TEST - -#include - -#include "avg.h" - -void test_add_single_val() { - int val = 42; - avg_add(val); - TEST_ASSERT_EQUAL(avg_get(), 42); -} - -int main( int argc, char **argv) { - UNITY_BEGIN(); - RUN_TEST(test_add_single_val); - UNITY_END(); -} - -#endif diff --git a/exercises/MQTT/mqtt.crt b/exercises/05_mqtt/mqtt.crt similarity index 100% rename from exercises/MQTT/mqtt.crt rename to exercises/05_mqtt/mqtt.crt diff --git a/exercises/MQTT/mqtt.crt.zip b/exercises/05_mqtt/mqtt.crt.zip similarity index 100% rename from exercises/MQTT/mqtt.crt.zip rename to exercises/05_mqtt/mqtt.crt.zip diff --git a/exercises/MQTT/arduino/ESP32-MQTT-TLS/.gitignore b/exercises/MQTT/arduino/ESP32-MQTT-TLS/.gitignore deleted file mode 100644 index 2de98ab..0000000 --- a/exercises/MQTT/arduino/ESP32-MQTT-TLS/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -.pio -.pioenvs -.piolibdeps -.vscode/.browse.c_cpp.db* -.vscode/c_cpp_properties.json -.vscode/launch.json diff --git a/exercises/MQTT/arduino/ESP32-MQTT-TLS/include/README b/exercises/MQTT/arduino/ESP32-MQTT-TLS/include/README deleted file mode 100644 index 194dcd4..0000000 --- a/exercises/MQTT/arduino/ESP32-MQTT-TLS/include/README +++ /dev/null @@ -1,39 +0,0 @@ - -This directory is intended for project header files. - -A header file is a file containing C declarations and macro definitions -to be shared between several project source files. You request the use of a -header file in your project source file (C, C++, etc) located in `src` folder -by including it, with the C preprocessing directive `#include'. - -```src/main.c - -#include "header.h" - -int main (void) -{ - ... -} -``` - -Including a header file produces the same results as copying the header file -into each source file that needs it. Such copying would be time-consuming -and error-prone. With a header file, the related declarations appear -in only one place. If they need to be changed, they can be changed in one -place, and programs that include the header file will automatically use the -new version when next recompiled. The header file eliminates the labor of -finding and changing all the copies as well as the risk that a failure to -find one copy will result in inconsistencies within a program. - -In C, the usual convention is to give header files names that end with `.h'. -It is most portable to use only letters, digits, dashes, and underscores in -header file names, and at most one dot. - -Read more about using header files in official GCC documentation: - -* Include Syntax -* Include Operation -* Once-Only Headers -* Computed Includes - -https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/exercises/MQTT/arduino/ESP32-MQTT-TLS/lib/README b/exercises/MQTT/arduino/ESP32-MQTT-TLS/lib/README deleted file mode 100644 index 6debab1..0000000 --- a/exercises/MQTT/arduino/ESP32-MQTT-TLS/lib/README +++ /dev/null @@ -1,46 +0,0 @@ - -This directory is intended for project specific (private) libraries. -PlatformIO will compile them to static libraries and link into executable file. - -The source code of each library should be placed in a an own separate directory -("lib/your_library_name/[here are source files]"). - -For example, see a structure of the following two libraries `Foo` and `Bar`: - -|--lib -| | -| |--Bar -| | |--docs -| | |--examples -| | |--src -| | |- Bar.c -| | |- Bar.h -| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html -| | -| |--Foo -| | |- Foo.c -| | |- Foo.h -| | -| |- README --> THIS FILE -| -|- platformio.ini -|--src - |- main.c - -and a contents of `src/main.c`: -``` -#include -#include - -int main (void) -{ - ... -} - -``` - -PlatformIO Library Dependency Finder will find automatically dependent -libraries scanning project source files. - -More information about PlatformIO Library Dependency Finder -- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/exercises/MQTT/arduino/ESP32-MQTT-TLS/platformio.ini b/exercises/MQTT/arduino/ESP32-MQTT-TLS/platformio.ini deleted file mode 100644 index 30d108f..0000000 --- a/exercises/MQTT/arduino/ESP32-MQTT-TLS/platformio.ini +++ /dev/null @@ -1,30 +0,0 @@ -; PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html - -[env:lolin32] -platform = espressif32 -board = lolin32 -framework = arduino - -lib_deps = - Wire - Time - ESP8266_SSD1306 - PubSubClient - - -build_flags = - -IC:/Users/Chris/.platformio/lib/ESP8266_SSD1306_ID562/ - -IC:/Users/Chris/.platformio/lib/Time_ID44/ - -;; http://docs.platformio.org/en/latest/projectconf/section_env_build.html#src-filter -src_filter = - +<*> -<.git/> - - - - - - - diff --git a/exercises/MQTT/arduino/ESP32-MQTT-TLS/src/main.cpp b/exercises/MQTT/arduino/ESP32-MQTT-TLS/src/main.cpp deleted file mode 100644 index d583eb3..0000000 --- a/exercises/MQTT/arduino/ESP32-MQTT-TLS/src/main.cpp +++ /dev/null @@ -1,198 +0,0 @@ -// Chris Bass -// 24/01/2019 -// ESP32 OLED (Wemos Lolin32) -// Secure encrypted MQTT with TLS/SSL - -#include - -#include -#include -#include - -#include // Only needed for Arduino 1.6.5 and earlier -#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"` - -// Initialize the OLED display using Wire library -SSD1306 display(0x3c, 5, 4); - -// WiFi ssid and password, change it with your ssid and password: -const char* ssid = "ECL-LEGO-ROBOTS"; // Lego WiFi -const char* password = "9cjjp64270"; // Lego WiFi - -// MQTT IP address of the PC/raspberry where you installed MQTT Server: -const char* mqttServer = "mqtt.coventry.ac.uk"; -const char* clientId = "ESP32Client"; // unique client ID for this device -const char* mqttUsername = "add_your_username_here"; -const char* mqttPassword = "add_your_password_here"; - -// TLS/SSL certificate for encrypted mqtt: -const char* ca_cert = \ - "-----BEGIN CERTIFICATE-----\n" \ - "MIIFYDCCA0igAwIBAgIURFc0JFuBiZs18s64KztbpybwdSgwDQYJKoZIhvcNAQEL\n" \ - "BQAwSDELMAkGA1UEBhMCQk0xGTAXBgNVBAoTEFF1b1ZhZGlzIExpbWl0ZWQxHjAc\n" \ - "BgNVBAMTFVF1b1ZhZGlzIFJvb3QgQ0EgMiBHMzAeFw0xMjAxMTIxODU5MzJaFw00\n" \ - "MjAxMTIxODU5MzJaMEgxCzAJBgNVBAYTAkJNMRkwFwYDVQQKExBRdW9WYWRpcyBM\n" \ - "aW1pdGVkMR4wHAYDVQQDExVRdW9WYWRpcyBSb290IENBIDIgRzMwggIiMA0GCSqG\n" \ - "SIb3DQEBAQUAA4ICDwAwggIKAoICAQChriWyARjcV4g/Ruv5r+LrI3HimtFhZiFf\n" \ - "qq8nUeVuGxbULX1QsFN3vXg6YOJkApt8hpvWGo6t/x8Vf9WVHhLL5hSEBMHfNrMW\n" \ - "n4rjyduYNM7YMxcoRvynyfDStNVNCXJJ+fKH46nafaF9a7I6JaltUkSs+L5u+9ym\n" \ - "c5GQYaYDFCDy54ejiK2toIz/pgslUiXnFgHVy7g1gQyjO/Dh4fxaXc6AcW34Sas+\n" \ - "O7q414AB+6XrW7PFXmAqMaCvN+ggOp+oMiwMzAkd056OXbxMmO7FGmh77FOm6RQ1\n" \ - "o9/NgJ8MSPsc9PG/Srj61YxxSscfrf5BmrODXfKEVu+lV0POKa2Mq1W/xPtbAd0j\n" \ - "IaFYAI7D0GoT7RPjEiuA3GfmlbLNHiJuKvhB1PLKFAeNilUSxmn1uIZoL1NesNKq\n" \ - "IcGY5jDjZ1XHm26sGahVpkUG0CM62+tlXSoREfA7T8pt9DTEceT/AFr2XK4jYIVz\n" \ - "8eQQsSWu1ZK7E8EM4DnatDlXtas1qnIhO4M15zHfeiFuuDIIfR0ykRVKYnLP43eh\n" \ - "vNURG3YBZwjgQQvD6xVu+KQZ2aKrr+InUlYrAoosFCT5v0ICvybIxo/gbjh9Uy3l\n" \ - "7ZizlWNof/k19N+IxWA1ksB8aRxhlRbQ694Lrz4EEEVlWFA4r0jyWbYW8jwNkALG\n" \ - "cC4BrTwV1wIDAQABo0IwQDAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIB\n" \ - "BjAdBgNVHQ4EFgQU7edvdlq/YOxJW8ald7tyFnGbxD0wDQYJKoZIhvcNAQELBQAD\n" \ - "ggIBAJHfgD9DCX5xwvfrs4iP4VGyvD11+ShdyLyZm3tdquXK4Qr36LLTn91nMX66\n" \ - "AarHakE7kNQIXLJgapDwyM4DYvmL7ftuKtwGTTwpD4kWilhMSA/ohGHqPHKmd+RC\n" \ - "roijQ1h5fq7KpVMNqT1wvSAZYaRsOPxDMuHBR//47PERIjKWnML2W2mWeyAMQ0Ga\n" \ - "W/ZZGYjeVYg3UQt4XAoeo0L9x52ID8DyeAIkVJOviYeIyUqAHerQbj5hLja7NQ4n\n" \ - "lv1mNDthcnPxFlxHBlRJAHpYErAK74X9sbgzdWqTHBLmYF5vHX/JHyPLhGGfHoJE\n" \ - "+V+tYlUkmlKY7VHnoX6XOuYvHxHaU4AshZ6rNRDbIl9qxV6XU/IyAgkwo1jwDQHV\n" \ - "csaxfGl7w/U2Rcxhbl5MlMVerugOXou/983g7aEOGzPuVBj+D77vfoRrQ+NwmNtd\n" \ - "dbINWQeFFSM51vHfqSYP1kjHs6Yi9TM3WpVHn3u6GBVv/9YUZINJ0gpnIdsPNWNg\n" \ - "KCLjsZWDzYWm3S8P52dSbrsvhXz1SnPnxT7AvSESBT/8twNJAlvIJebiVDj1eYeM\n" \ - "HVOyToV7BjjHLPj4sHKNJeV3UvQDHEimUF+IIDBu8oJDqz2XhOdT+yHBTw8imoa4\n" \ - "WSr2Rz0ZiC3oheGe7IUIarFsNMkd7EgrO3jtZsSOeWmD3n+M\n" \ - "-----END CERTIFICATE-----\n"; - - -WiFiClientSecure espClient; -PubSubClient mqttClient(espClient); - -long lastMsg = 0; - -// The receivedCallback() function will be invoked when this client receives data about the subscribed topic -void receivedCallback(char* topic, byte* payload, unsigned int length) { - Serial.print("Message received: "); - Serial.println(topic); - - Serial.print("payload: "); - for (int i = 0; i < length; i++) { - Serial.print((char)payload[i]); - } - Serial.println(); - - display.clear(); - display.drawString(0, 0, "receivedCallback"); - display.drawString(0, 10, "topic: " + String(topic)); - display.drawString(0, 20, "payload:"); - for (int i = 0; i < length; i++) { - display.drawString(i*6, 30, String((char)payload[i])); - } - display.display(); - delay(1000); - -} - -// Will attempt to connect to MQTT and subscribe to a topic feed -void mqttConnect() { - // Loop until reconnected - while (!mqttClient.connected()) { - - display.clear(); - display.drawString(0, 0, "In mqttConnect()"); - display.drawString(0, 10, "MQTT connecting..."); - display.display(); - - if (mqttClient.connect(clientId, mqttUsername, mqttPassword)) { - display.drawString(0, 20, "...connected"); - display.display(); - delay(1000); - // Subscribe topic with default QoS 0 - // Let's just subscribe to the same feed we are publishing to, to see if our message gets recorded. - mqttClient.subscribe("302CEM/aa6164/mydata"); // topic name MUST be in the format: 302CEM// - //mqttClient.subscribe("302CEM/aa6164/feeds/mydata2"); // topic name MUST be in the format: 302CEM// - - } else { - display.drawString(0, 20, "...connect failed, status code ="); - display.drawString(0, 30, String(mqttClient.state())); - display.drawString(0, 40, "try again in 5 seconds"); - display.display(); - delay(5000); // Wait 5 seconds before retrying - } - } -} - -void setup() { - // Initialising the UI will init the display too. - display.init(); - //display.flipScreenVertically(); - display.setFont(ArialMT_Plain_10); - display.setTextAlignment(TEXT_ALIGN_LEFT); - display.clear(); - display.drawString(0, 0, "Hello WiFi"); - display.drawString(0, 10, "Attempting to connect to:"); - display.drawString(0, 20, String(ssid)); - display.display(); - delay(500); - - Serial.begin(115200); - Serial.println(); - Serial.print("Connecting to "); - Serial.println(ssid); - - // We start by connecting to a WiFi network - WiFi.begin(ssid, password); - - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); - } - - Serial.println(""); - Serial.println("WiFi connected"); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - - display.clear(); - display.drawString(0, 0, "WiFi connected"); - display.drawString(0, 10, "IP address: " + WiFi.localIP().toString()); - display.drawString(0, 20, "Setting up MQTT..."); - display.display(); - delay(3000); - - // We need a certificate in order to do a secure TLS/SSL connection to our server - espClient.setCACert(ca_cert); - - // Port 1883 is reserved with IANA for use with MQTT. - // TCP/IP port 8883 is also registered, for using MQTT over SSL. - //mqttClient.setServer(mqttServer, 1883); - - // help url: http://www.iotsharing.com/2017/08/how-to-use-esp32-mqtts-with-mqtts-mosquitto-broker-tls-ssl.html - mqttClient.setServer(mqttServer, 8883); // Port 8883 for MQTT over SSL. - - // The receivedCallback() function will be invoked when this client receives the subscribed topic: - mqttClient.setCallback(receivedCallback); -} - -void loop() { - display.clear(); - display.drawString(0, 0, "Hello world: " + String(millis())); - display.display(); - delay(10); - - // if client was disconnected then try to reconnect again - if (!mqttClient.connected()) { - mqttConnect(); // displays on line 0, 1 and 2 - } - // this function will listen for incoming subscribed topic-process-invoke receivedCallback() - mqttClient.loop(); - - // we send a reading every 5 secs - // we count until 5 secs reached to avoid blocking program if using delay() - long now = millis(); - if (now - lastMsg > 5000) { - lastMsg = now; - String dataToSend = String(millis()); // dataToSend could be a sensor reading instead - display.drawString(0, 50, "Sending data: " + dataToSend); - display.display(); - // just convert time stamp to a c-string and send as data: - mqttClient.publish("302CEM/aa6164/mydata", dataToSend.c_str()); - delay(2000); - } -} - diff --git a/exercises/MQTT/arduino/ESP32-MQTT-TLS/test/README b/exercises/MQTT/arduino/ESP32-MQTT-TLS/test/README deleted file mode 100644 index df5066e..0000000 --- a/exercises/MQTT/arduino/ESP32-MQTT-TLS/test/README +++ /dev/null @@ -1,11 +0,0 @@ - -This directory is intended for PIO Unit Testing and project tests. - -Unit Testing is a software testing method by which individual units of -source code, sets of one or more MCU program modules together with associated -control data, usage procedures, and operating procedures, are tested to -determine whether they are fit for use. Unit testing finds problems early -in the development cycle. - -More information about PIO Unit Testing: -- https://docs.platformio.org/page/plus/unit-testing.html diff --git a/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/.gitignore b/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/.gitignore deleted file mode 100644 index 2de98ab..0000000 --- a/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -.pio -.pioenvs -.piolibdeps -.vscode/.browse.c_cpp.db* -.vscode/c_cpp_properties.json -.vscode/launch.json diff --git a/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/include/README b/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/include/README deleted file mode 100644 index 194dcd4..0000000 --- a/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/include/README +++ /dev/null @@ -1,39 +0,0 @@ - -This directory is intended for project header files. - -A header file is a file containing C declarations and macro definitions -to be shared between several project source files. You request the use of a -header file in your project source file (C, C++, etc) located in `src` folder -by including it, with the C preprocessing directive `#include'. - -```src/main.c - -#include "header.h" - -int main (void) -{ - ... -} -``` - -Including a header file produces the same results as copying the header file -into each source file that needs it. Such copying would be time-consuming -and error-prone. With a header file, the related declarations appear -in only one place. If they need to be changed, they can be changed in one -place, and programs that include the header file will automatically use the -new version when next recompiled. The header file eliminates the labor of -finding and changing all the copies as well as the risk that a failure to -find one copy will result in inconsistencies within a program. - -In C, the usual convention is to give header files names that end with `.h'. -It is most portable to use only letters, digits, dashes, and underscores in -header file names, and at most one dot. - -Read more about using header files in official GCC documentation: - -* Include Syntax -* Include Operation -* Once-Only Headers -* Computed Includes - -https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/lib/README b/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/lib/README deleted file mode 100644 index 6debab1..0000000 --- a/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/lib/README +++ /dev/null @@ -1,46 +0,0 @@ - -This directory is intended for project specific (private) libraries. -PlatformIO will compile them to static libraries and link into executable file. - -The source code of each library should be placed in a an own separate directory -("lib/your_library_name/[here are source files]"). - -For example, see a structure of the following two libraries `Foo` and `Bar`: - -|--lib -| | -| |--Bar -| | |--docs -| | |--examples -| | |--src -| | |- Bar.c -| | |- Bar.h -| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html -| | -| |--Foo -| | |- Foo.c -| | |- Foo.h -| | -| |- README --> THIS FILE -| -|- platformio.ini -|--src - |- main.c - -and a contents of `src/main.c`: -``` -#include -#include - -int main (void) -{ - ... -} - -``` - -PlatformIO Library Dependency Finder will find automatically dependent -libraries scanning project source files. - -More information about PlatformIO Library Dependency Finder -- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/platformio.ini b/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/platformio.ini deleted file mode 100644 index 99c5179..0000000 --- a/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/platformio.ini +++ /dev/null @@ -1,20 +0,0 @@ -; PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html - -[env:lolin32] -platform = espressif32 -board = lolin32 -framework = arduino - -lib_deps = - RadioHead - Wire - ESP8266_SSD1306 - \ No newline at end of file diff --git a/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/src/receiver.cpp b/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/src/receiver.cpp deleted file mode 100644 index 793f9ce..0000000 --- a/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/src/receiver.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// receiver.cpp -// Seperate Transmitter and Receiver programs need to be running on seperate ESP32 nodes. -// Might be possible to run both on a single ESP32 if we make use of threading? -// This is the receiver.cpp code: -// Chris Bass -// 06/03/2019 - -// Example from RadioHead library to receive messages with a simple ASK. -// Implements a simplex (one-way) receiver with an Rx-B1 module - -#include -#include -#include // Not actually used but needed to compile - -#include // Only needed for Arduino 1.6.5 and earlier -#include // alias for `#include "SSD1306Wire.h"` - -SSD1306 display(0x3c, 5, 4); // OLED display - -// (speed, rxPin, txPin, pttPin); -RH_ASK driver(2000, 2, 4, 5); // ESP8266 or ESP32: do not use pin 11 - -void setup() -{ - Serial.begin(9600); // Debugging only - - display.init(); - //display.flipScreenVertically(); - display.setFont(ArialMT_Plain_10); - display.setTextAlignment(TEXT_ALIGN_LEFT); - display.clear(); - display.drawString(0, 0, "Hello 433MHz Radio"); - display.drawString(0, 10, "Receive on rxPin 2"); - display.display(); - - if (!driver.init()) { - Serial.println("init failed"); - display.drawString(0, 20, "init failed"); - } - - display.display(); - -} - -void loop() -{ - // do a receieve - uint8_t buf[RH_ASK_MAX_MESSAGE_LEN]; - uint8_t buflen = sizeof(buf); - - if (driver.recv(buf, &buflen)) // Non-blocking - { - int i; - - // Message with a good checksum received, dump it. - driver.printBuffer("Got:", buf, buflen); - Serial.println("received..."); - - display.clear(); - display.drawString(0, 0, "Receiving on rxPin 2"); - display.drawString(0, 10, "Received:"); - std::string toDraw(buf, buf + buflen); - display.drawString(0, 20, toDraw.c_str()); - display.display(); - - } else { - Serial.println("driver.recv() returned false"); - } - - -} diff --git a/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/src/transmitter.cpp b/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/src/transmitter.cpp deleted file mode 100644 index 6c8a53d..0000000 --- a/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/src/transmitter.cpp +++ /dev/null @@ -1,79 +0,0 @@ -// transmitter.cpp -// Seperate Transmitter and Receiver programs need to be running on seperate ESP32 nodes. -// Might be possible to run both on a single ESP32 if we make use of threading? -// This is the transmitter.cpp code -// Chris Bass -// 06/03/2019 - -// Example from RadioHead library to transmit messages with a simple ASK. -// Implements a simplex (one-way) transmitter with an TX-C1 module - -#include -#include -#include // Not actually used but needed to compile - -#include // Only needed for Arduino 1.6.5 and earlier -#include // alias for `#include "SSD1306Wire.h"` - -#include - -SSD1306 display(0x3c, 5, 4); // OLED display - -// (speed, rxPin, txPin, pttPin); -RH_ASK driver(2000, 2, 4, 5); // ESP8266 or ESP32: do not use pin 11 - -unsigned long previousMillis = 0; -const long interval = 1000; // interval period at which to transmit (milliseconds) - -void setup() -{ - Serial.begin(9600); // Debugging only - - display.init(); - //display.flipScreenVertically(); - display.setFont(ArialMT_Plain_10); - display.setTextAlignment(TEXT_ALIGN_LEFT); - display.clear(); - display.drawString(0, 0, "Hello 433MHz Radio"); - display.drawString(0, 10, "Transmit on txPin 4"); - display.display(); - - if (!driver.init()) { - Serial.println("init failed"); - display.drawString(0, 20, "init failed"); - } - - display.display(); - -} - -void loop() -{ - // every interval do a transmit: - unsigned long currentMillis = millis(); - if (currentMillis - previousMillis >= interval) { - previousMillis = currentMillis; - - //const char *msg = "hello"; //(String("hello") + String(millis())).c_str(); - std::string msgToSend; - std::stringstream ss; - ss << "hello " << millis(); - msgToSend = ss.str(); - std::vector myVector(msgToSend.begin(), msgToSend.end()); - uint8_t *msgPtr = &myVector[0]; - - Serial.print("sending..."); - Serial.println(msgToSend.c_str()); - - display.clear(); - display.drawString(0, 0, "Transmitting from txPin 4"); - display.drawString(0, 10, "Sending:"); - display.drawString(0, 20, msgToSend.c_str()); - display.display(); - - driver.send(msgPtr, msgToSend.length()); //strlen(msg)); - driver.waitPacketSent(); - delay(200); - } - -} diff --git a/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/test/README b/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/test/README deleted file mode 100644 index df5066e..0000000 --- a/exercises/MQTT/arduino/ESP32-OLED-433MHz-Radio/test/README +++ /dev/null @@ -1,11 +0,0 @@ - -This directory is intended for PIO Unit Testing and project tests. - -Unit Testing is a software testing method by which individual units of -source code, sets of one or more MCU program modules together with associated -control data, usage procedures, and operating procedures, are tested to -determine whether they are fit for use. Unit testing finds problems early -in the development cycle. - -More information about PIO Unit Testing: -- https://docs.platformio.org/page/plus/unit-testing.html diff --git a/exercises/MQTT/arduino/blink/.vscode/extensions.json b/exercises/MQTT/arduino/blink/.vscode/extensions.json deleted file mode 100644 index 8281e64..0000000 --- a/exercises/MQTT/arduino/blink/.vscode/extensions.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "platformio.platformio-ide" - ] -} \ No newline at end of file diff --git a/exercises/MQTT/arduino/blink/.vscode/settings.json b/exercises/MQTT/arduino/blink/.vscode/settings.json deleted file mode 100644 index b15d089..0000000 --- a/exercises/MQTT/arduino/blink/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "terminal.integrated.env.linux": { - "PATH": "/home/mtyers/.platformio/penv/bin:/home/mtyers/.platformio/penv:/home/mtyers/.platformio/penv/bin:/home/mtyers/.platformio/penv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin", - "PLATFORMIO_CALLER": "vscode" - } -} \ No newline at end of file diff --git a/exercises/MQTT/arduino/blink/include/readme.txt b/exercises/MQTT/arduino/blink/include/readme.txt deleted file mode 100644 index 194dcd4..0000000 --- a/exercises/MQTT/arduino/blink/include/readme.txt +++ /dev/null @@ -1,39 +0,0 @@ - -This directory is intended for project header files. - -A header file is a file containing C declarations and macro definitions -to be shared between several project source files. You request the use of a -header file in your project source file (C, C++, etc) located in `src` folder -by including it, with the C preprocessing directive `#include'. - -```src/main.c - -#include "header.h" - -int main (void) -{ - ... -} -``` - -Including a header file produces the same results as copying the header file -into each source file that needs it. Such copying would be time-consuming -and error-prone. With a header file, the related declarations appear -in only one place. If they need to be changed, they can be changed in one -place, and programs that include the header file will automatically use the -new version when next recompiled. The header file eliminates the labor of -finding and changing all the copies as well as the risk that a failure to -find one copy will result in inconsistencies within a program. - -In C, the usual convention is to give header files names that end with `.h'. -It is most portable to use only letters, digits, dashes, and underscores in -header file names, and at most one dot. - -Read more about using header files in official GCC documentation: - -* Include Syntax -* Include Operation -* Once-Only Headers -* Computed Includes - -https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/exercises/MQTT/arduino/blink/lib/readme.txt b/exercises/MQTT/arduino/blink/lib/readme.txt deleted file mode 100644 index c3fd443..0000000 --- a/exercises/MQTT/arduino/blink/lib/readme.txt +++ /dev/null @@ -1,46 +0,0 @@ - -This directory is intended for project specific (private) libraries. -PlatformIO will compile them to static libraries and link into executable file. - -The source code of each library should be placed in a an own separate directory -("lib/your_library_name/[here are source files]"). - -For example, see a structure of the following two libraries `Foo` and `Bar`: - -|--lib -| | -| |--Bar -| | |--docs -| | |--examples -| | |--src -| | |- Bar.c -| | |- Bar.h -| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html -| | -| |--Foo -| | |- Foo.c -| | |- Foo.h -| | -| |- readme.txt --> THIS FILE -| -|- platformio.ini -|--src - |- main.c - -and a contents of `src/main.c`: -``` -#include -#include - -int main (void) -{ - ... -} - -``` - -PlatformIO Library Dependency Finder will find automatically dependent -libraries scanning project source files. - -More information about PlatformIO Library Dependency Finder -- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/exercises/MQTT/arduino/blink/platformio.ini b/exercises/MQTT/arduino/blink/platformio.ini deleted file mode 100644 index 64027ca..0000000 --- a/exercises/MQTT/arduino/blink/platformio.ini +++ /dev/null @@ -1,23 +0,0 @@ -; PlatformIO Project Configuration File -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html - -;monitor_speed = 9600 - -[env:nodemcuv2] -platform = espressif8266 -board = nodemcuv2 -framework = arduino -; upload_port = /dev/ttyUSB0 -upload_speed = 57600 ; 9600 14400 19200 28800 38400 57600 115200 - -[env:lolin32] -platform = espressif32 -board = lolin32 -framework = arduino -; upload_port = /dev/ttyUSB0 -upload_speed = 115200 ; 9600 14400 19200 28800 38400 57600 115200 - -[env:native] -platform = native diff --git a/exercises/MQTT/arduino/blink/readme.md b/exercises/MQTT/arduino/blink/readme.md deleted file mode 100644 index b595362..0000000 --- a/exercises/MQTT/arduino/blink/readme.md +++ /dev/null @@ -1,22 +0,0 @@ - -# Notes - -The platformio commands are stored in this directory: - -~/.platformio/penv/bin - -commands: - -Starting a project for the NodeMCU v2 environment: - -platformio init -b nodemcuv2 - -To flash to a device: - -$ pio run -e nodemcuv2 - -HOw to run the tests: - -~/.platformio/penv/bin/pio test -e native - -https://www.thingforward.io/techblog/2017-07-25-starting-embedded-testing-with-platformio.html diff --git a/exercises/MQTT/arduino/blink/src/main.cpp b/exercises/MQTT/arduino/blink/src/main.cpp deleted file mode 100644 index 57403c8..0000000 --- a/exercises/MQTT/arduino/blink/src/main.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include - -long randNumber; - -void setup() { - Serial.begin(9600); - pinMode(D4, OUTPUT); // NodeMCU: D4, Lolin32: LED_BUILTIN - randomSeed(analogRead(0)); -} - -void loop() { - randNumber = random(10, 20); - Serial.println(randNumber); - digitalWrite(D4, HIGH); // remember to change this for Lolin32 - delay(1000); - digitalWrite(D4, LOW); // remember to change this for Lolin32 - delay(1000); -} diff --git a/exercises/MQTT/arduino/samples/00 Getting Started.md b/exercises/MQTT/arduino/samples/00 Getting Started.md deleted file mode 100644 index c181d10..0000000 --- a/exercises/MQTT/arduino/samples/00 Getting Started.md +++ /dev/null @@ -1,197 +0,0 @@ - -# Getting Started - -This guide is for anyone who has not used the NodeMCU with the Arduino IDE. It covers the setup and configuration of the IDE as well as demonstrating how to use the MQTT protocol to publish data to the Adafruit.io cloud platform. - -You will need to install drivers on your computer. Look on the base of the NodeCMU. If it states you need the **2102 driver**, you can download and install it from [here](https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers). - -Start by downloading and installing the [Arduino IDE](https://www.arduino.cc/en/Main/Software), this is version 1.8.5 at the time of writing. - -Next you need to add support for the **ESP8266 NodeMCU Development Board**: - -1. Open the Arduino IDE. -2. Choose the _Arduino > Preferences_ menu -3. Paste the following into the **Additional Boards Manager** box. - - `http://arduino.esp8266.com/stable/package_esp8266com_index.json` -4. Click on OK to close the Preferences window -5. open the _Tools > Boards > Board manager_ menu. - - find `esp8266 by esp8266 community` and install. -6. Open the _Tools > Board_ menu: - - choose the `NodeMCU 1.0 (ESP12-E Module)`. -7. Make a note of the available serial ports using the `Tools > Port` menu. -8. Plug in the NodeMCU development board. This will create a new virtual serial port (on a Mac is is labelled `/dev/cu.SLAB_USBtoUART` or something similar. Check the `Tools > Ports` menu again and select the port that has been added. - -## Hello World - -The next step is to compile and flash a simple sketch that will flash the onboard LED on and off. Enter the following code into the IDE. - -```cpp -void setup(void) { - Serial.begin(9600); - pinMode(2, OUTPUT); -} - -void loop() { - digitalWrite(2, HIGH); - delay(1000); - digitalWrite(2, LOW); - delay(1000); -} -``` - -Use the `Sketch > verify/compile` option to compile the code, there should not be any errors reported. - -Now you can flash the MCU with your cmpiled code using the `Sketch > Upload` menu option. - -As soon as the sketch has been flashed, open the _Tools > Serial monitor_ and change the baud rate to match that in the sketch (in this case it should be 9,600). - -### If Your Mac Crashes - -Many development boards including the NodeMCU v3 use the CH340 chipset for usb to serial communication. Unfortunately the official CH340 driver causes a _kernel panic_ (freeze and reboot) because the drivers are not signed correctly. The solution is to download and use a commercial driver from [Mac USB Serial](https://www.mac-usb-serial.com/) which costs $8. Before you buy this download and use the free test app to see if it recognises your NodeMCU. Unplug it, run the test app then plug in the NodeMCU, it should be recognised. - -## Connecting to the IO.Adafruit Server - -The next step is to publish some data to the [io.dafruit.com](https://io.adafruit.com) service. This is an MQTT broker which requires you to create an account before you can use it. Once you have an account you need to locate and copy your **username** and **AIO key** by clicking on the **View AIO Key** link . - -We will then need to install the correct library. Choose `Sketch > Include Library > Manage Library` and search for `adafruit MQTT` and click on the **install** button to install the latest version (0.20.1 at the time of writing). - -Once the library has been installed you can access a lot of sample sketches which will help you. A good starting point is the `File > Examples > Adafruit MQTT Library > mqtt_esp8266` sketch which shows you how to both publish to an MQTT topic as well as how to subscribe. Open this sketch and save it to a suitable location on your computer before making the following changes: - -1. Insert the **SSID** and **password** of your Wifi network where indicated. -2. Insert your **username** and **AIO Key** where shown. - -You can now compile and flash the sketch to your NodeMCU board. - -## Viewing the Data - -Make sure you are logged onto the [io.dafruit.com](https://io.adafruit.com) website and locate the **Feeds** tab. This shows you all the topics you are publishing to. You should see a topic called **photocell** which contains an incrementing number. Clicking on the name shows you a graph with the raw data displayed underneath. - -Congratulations, you are publishing data to the server! - -## Publishing Real Data - -Connect a DHT11 sensor and publish the temperature data to the cloud server... - -Now its time to wire up a _real_ sensor. In addition to the NodeMCU you will need a solderless breadboard and a DHT11 sensor as well as some jumper wires to connect everything together. - -![DHT11 Breadboard Wiring](../../.images/DHT11_breadboard.png) - -Notice that although the sensor has 4 pins we only need 3 of them. - -1. VCC/+ (connects to the 3.3v power rail) -2. DATA/OUT (connects to pin D4) -3. NC (not connected) -4. GND/- (connects to the ground rail) - -If your sensor is mounted on a breakout board it will only have 3 pins and these will be clearly labelled. - -DHT Sensor Library - -Now you need to install the `DHT sensor library by Adafruit`. - -using the code sample below (that sends the current temperature reading to the serial monitor) to publish the current temperature to the io.adafruit server? - -```cpp -#include -#include -#include - -DHT_Unified dht(D4, DHT11); - -void setup() { - Serial.begin(9600); - dht.begin(); -} - -void loop() { - delay(5000); - sensors_event_t event; - dht.temperature().getEvent(&event); - if (!isnan(event.temperature)) { - Serial.print("Temperature: "); - Serial.print(event.temperature); - Serial.println(" *C"); - } -} -``` - -## Creating a Dashboard - -Now it's time to build something useful. Click on the **Dashboards** tab. Notice that you have one dashboard called the _Welcome Dashboard_, you need to delete this and create a new one called `Environment`. - -Open this and use the blue `+` button to create a new block. Choose the _Line Chart_ and on the next screen check the **Temperature** feed. Click the **Next Step** button, accept the default options and click **Done**. You will see the graph displayed on your dashboard. - -## Subscribing to a Topic - -So far you have been viewing data that has been published by the NodeMCU. In this section you will be publishing from the io.adafruit web page and your NodeMCU will subscribe to these messages! - -If you examine the sample code you will see that there is already code that subscribes to the `/feeds/onoff` topic. Make sure you are on your **Environment** dashboard and use the blue `+` to button to create a new block. This time choose a **Toggle** and, in the popup window enter `onoff` in the box labelled _Enter new feed name_ and click on the blue **Create** button. - -Make sure the Arduino _Serial Monitor_ is open and displaying the sensor values. Slide the on/off switch to the on position, what is displayed in the serial monitor? Slide it back to _off_, what is displayed? Can you find the code in the sketch that is being triggered? - -## Battery Power - -You have probably noticed that as soon as you disconnect the USB cable the NodeMCU stop running. This is solely because you have removed the power being supplied through the USB cable. It is useful to do this during development however rather inconvenient to have to permanently attach it to your computer. There are two ways you can power the NodeMCU after you disconnect from the computer: - -1. Plug the NodeMCU into a USB power bank. -2. Use a breadboard power supply to provide 3.3v to the VIN pin. - -The best solution is to simply power the NodeMCU either using a microUSB power supply (wall wart) or using a phone power bank. - -### Using the Breadboard Power Supply - -Your IoT kit comes with a breadboard power supply that can supply either 3.3v or 5v to both power rails on the breadboard. - -**Make sure you set the two jumpers to supply 3.3v!** - -![DHT11 Breadboard Wiring](../../.images/DHT11_w_PSU.png) - -As you can see, the power is taken off the lower rail and supplied to the VIN pin, this powers the NodeMCU. This same rail also supplies the DHT11 sensor. - -Disconnect the USB cable and supply power to the power supply unit. This can be: - -1. A 9v battery (using the supplied battery clip). -2. 4x AA batteries (using the battery box in the kit). -3. A 'wall wart' mains power supply (between 5 and 9v). -4. Usb power by connecting using the USB connector. - -You can power the system on and off using the white power button. - -### Reducing Power Drain - -At the moment your NodeMCU is drawing full power all the time. To conserve power (and allow you to run for longer on a battery) there are a number of steps you can take. - -The first is to reduce the sensor sample rate, taking a reading consumes power. - -The second approach is to put the NodeMCU into **deep sleep** until we need to take another sensor reading. To do this you need to connect the - -Pulling the **RESET** button _LOW_ resets the microcontroller (the equivalent of switching it off and on again). There is also a `RST` button next to the USB connector which does this for you. The ESP8266 microcontroller can be put into a deep sleep mode for a predetermined time (measured in microseconds). During this time only the Real-Time Clock (RTC) is running as this is needed to work out when to end the deep sleep. Once the time is up the `WAKE` pin is pulled low. - -On the ESP8266 `D0` is the `wake` pin and `rst` is the reset pin. - -What this means in practice is that we need to wire these pins together so that when the timer is done, the WAKE pin goes low and restarts the MCU. However this means we have to make a critical change to our code! Since the MCU is reset, the setup() function is run each time and so we need to move the code from loop() to setup(), see the example below: - -```cpp -void setup() { - Serial.begin(9600); - Serial.setTimeout(2000); - while(!Serial) {} // wait for the serial connection... - Serial.println("I'm awake."); - Serial.println("Going into deep sleep for 20 seconds"); - ESP.deepSleep(20e6); -} - -void loop() {} -``` - -The parameter sent to `ESP.deepSleep()` is the number of microseconds to wait until pulling the `WAKE` pin low (restarting the MCU). `20e6` is scientific notation for 20 x 10 to the power of 6, 20,000,000 microseconds or 20 seconds. - -## Tracking Your Data - -Set up your remote sensor module somewhere safe and install the [DataFeeds app](https://itunes.apple.com/us/app/datafeeds-a-feed-monitor-for-adafruit-io/id1163614771?mt=8). By entering your AIO key you can monitor the data feeds on your smartphone! - -## References - -https://openhomeautomation.net/esp8266-battery - -https://www.losant.com/blog/making-the-esp8266-low-powered-with-deep-sleep \ No newline at end of file diff --git a/exercises/MQTT/arduino/samples/01 Lab 1 Arduino Introduction.md b/exercises/MQTT/arduino/samples/01 Lab 1 Arduino Introduction.md deleted file mode 100644 index b40309c..0000000 --- a/exercises/MQTT/arduino/samples/01 Lab 1 Arduino Introduction.md +++ /dev/null @@ -1,61 +0,0 @@ - -# Introduction to the Arduino PLatform - -In this lab you will be learning how to program the NodeMCU development board which is based on the ESP8266 module. You will find one of these development boards in your IoT kit, they look like this. - -![NodeMCU Comparison](../../.images/nodemcu.jpg) - -As you can see there are two versions, v2 and v3, make sure you know which version you are using. - -You should start by installing the latest version of the Visual Studio Code IDE (not Visual Studio). Open this and locate the Extensions tab from the left-hand edge. - -![Extensions Tab](../../.images/extensions.png) - -Search for and install the **PlatformIO IDE**. This will add an extra tab on the left-hand edge of the editor which can be used to launch the plugin. - -## Linux Setup - -Linux users have to install udev rules for PlatformIO supported boards/devices. - -```shell -$ curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/develop/scripts/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules -$ sudo service udev restart -$ sudo usermod -a -G dialout $USER -$ sudo usermod -a -G plugdev $USER -``` - -At this point you should unplug the board and reconnect. - -## Creating a new Project - -From the home screen choose **New Project**. Call it `hello` and locate the **NodeMCU 1.0** board (if you start typing in the box it searches the available boards). - -![Project Wizard](../../.images/project_wizard.png) - -This will create a project in your documents directory. - -Open this directory using Visual Studio Code and locate the `main.cpp` file in the `src/` directory. Modify the script to the following: - -```cpp -#include - -void setup() { - Serial.begin(9600); - pinMode(2, OUTPUT); -} - -void loop() { - digitalWrite(2, HIGH); - delay(1000); - digitalWrite(2, LOW); - delay(1000); -} -``` - -## Uploading the Sketch - -There are a row of buttons in the editor's status bar. Hover over each of these in turn to show the tooltip to understand their purpose. Click on the **PlatformIO: Upload button to compile the sketch and upload to the attached board. - -![PlatformIO Buttons](../../.images/platformio_buttons.png) - -As soon as the sketch has uploaded it will start running. You should see the onboard LED flashing on and off. diff --git a/exercises/MQTT/arduino/samples/01 SENSORS b/exercises/MQTT/arduino/samples/01 SENSORS deleted file mode 100644 index e69de29..0000000 diff --git a/exercises/MQTT/arduino/samples/02 SENSORS b/exercises/MQTT/arduino/samples/02 SENSORS deleted file mode 100644 index e69de29..0000000 diff --git a/exercises/MQTT/arduino/samples/03 SENSORS b/exercises/MQTT/arduino/samples/03 SENSORS deleted file mode 100644 index e69de29..0000000 diff --git a/exercises/MQTT/arduino/samples/04 SENSORS I2C.md b/exercises/MQTT/arduino/samples/04 SENSORS I2C.md deleted file mode 100644 index 349dcec..0000000 --- a/exercises/MQTT/arduino/samples/04 SENSORS I2C.md +++ /dev/null @@ -1,61 +0,0 @@ -# The I2C Bus - -The I2C communication bus is used by many electronic devices. It allows communication between a master and multiple slave devices using only two wires. This works because each device has a unique device address so the master can choose with which devices will be communicating. - -Each I2C component has a default address which can be found on the [Master I2C Address List](https://learn.adafruit.com/i2c-addresses/the-list). - -The two wires, or lines are called Serial Clock (or SCL) and Serial Data (or SDA). The SCL line is the clock signal which synchronize the data transfer between the devices on the I2C bus and it’s generated by the master device. The other line is the SDA line which carries the data. - -Multiple devices can be daisychained using the same `SCL` and `SDA` pins. You can have a maximum of one controller and up to 127 devices sharing the same bus. - - Each MCU has the two pins pre-defined. On the NodeMCU v2 the SCL is pin `D1` and SDA is pin `D2`. - - ![SSD1306 Screen Connections](../../.images/ssd1306_screen.png) - -http://www.robot-electronics.co.uk/i2c-tutorial - -## Using the SSD1306 OLED Screen - -I2C communication on the Arduino platform uses the `Wire` library. You will need to install this plus the `Adafruit SSD1306` library which handles formatting the data to display as text on the screen. - -The SSD1306 uses address `0x3C`. - -```cpp - -#include -#include -#include - -#define OLED_RESET LED_BUILTIN -Adafruit_SSD1306 display(OLED_RESET); - -void setup() { - // 0x3C is the defaultI2C address for an SSD1306 display - display.begin(SSD1306_SWITCHCAPVCC, 0x3C); - - // Clear the buffer. - display.clearDisplay(); - display.display(); - - display.setTextSize(1); - display.setTextColor(WHITE); - display.setCursor(0,0); - display.println("Hello from:"); - display.setTextSize(2); - display.setCursor(10, 20); - display.println("Coventry"); - display.println("University"); - display.display(); - -} - -void loop() {} -``` - -http://arduino-er.blogspot.co.uk/2016/04/nodemcu-esp8266-to-display-on-128x64.html - -## Commecting the VEML6070 UV Sensor - -Install the `Adafruit VEML6070` library. - - diff --git a/exercises/MQTT/arduino/samples/05 SENSORS b/exercises/MQTT/arduino/samples/05 SENSORS deleted file mode 100644 index e69de29..0000000 diff --git a/exercises/MQTT/arduino/samples/06 SENSORS b/exercises/MQTT/arduino/samples/06 SENSORS deleted file mode 100644 index e69de29..0000000 diff --git a/exercises/MQTT/arduino/samples/07 Interrupts.md b/exercises/MQTT/arduino/samples/07 Interrupts.md deleted file mode 100644 index 89c4319..0000000 --- a/exercises/MQTT/arduino/samples/07 Interrupts.md +++ /dev/null @@ -1,103 +0,0 @@ - -# Interrupts - -interrupts are events or conditions that cause the microprocessor or microcontroller to stop the execution of the task that it is performing, work in a different task temporarily and come back to the initial task. This means the microcontroller can respond to signals without the need for _polling_. In traditional programming terms interrupts server the same purpose as _event handlers_. - -When an interrupt is triggered we handle it in an Interrupt Service Routine (ISR). - -When working with arduino there are two types of interupt: - -1. External Interrupts are triggered on the logic state changing on an external pin. These are good when you are waiting for an external signal to run a block of code. -2. Timer Interupts are triggered at a predetermined interval based on the MCU clock signal. These are good when you want to trigger a block of code at specific intervals. - -## 1 External Interrupts - -The ESP8266 microcontroller has a number of General Purpose Input/Output (GPIO) pins. As you can see from the pinout diagram below these don't match the pin labels on the breakout board. - -![NodeMCU Pinout](../../.images/nodemcu_pins.png) - -In our example we define `GPIO13` as our interrup which corresponds to the `D7` pin on the breakout board and use the [attachInterrupt() function](https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/) to attach the interupt to the specified pin. This takes 3 parameters: - -1. The GPIO pin to attach the interupt to. -2. The Interupt Service Routine (ISR) to attach. -3. The _mode_, defining when the interrupt should be triggered (LOW, CHANGE, RISING, FALLING). - -Here is a simple example that attaches an interrupt to pin `D7` corresponding to GPIO13 and outputs to the serial monitor: - -```cpp -const byte interruptPin = 13; -volatile byte interruptCounter = 0; -int numberOfInterrupts = 0; - -void setup() { - Serial.begin(9600); - pinMode(interruptPin, INPUT_PULLUP); - attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING); -} - -void handleInterrupt() { - interruptCounter++; -} - -void loop() { - if(interruptCounter > 0){ - interruptCounter--; - numberOfInterrupts++; - Serial.print("An interrupt has occurred. Total: "); - Serial.println(numberOfInterrupts); - } -} -``` - -You can test this by using a wire to connect the `G` (ground) pin to `D7`. Each time you do this it triggers the interrupt and you should see this output to the serial monitor. - -### Debouncing - -If you try out this example you will see that each time you connect `G` to `D7`, you get multiple interrupts. This is because as you manually touch the pin it _bounces_, creating multiple signals. To resolve this you would need to implement either a debounce circuit that removes these in the switch or do it in software. - -### 1.1 Test Your Understanding - -Your kit contains a simple Anemometer to measure wind speed. It is supplied with a cable that terminates at an RJ11 connector. If you examine this connector you will see that only the middle 2 pins are in use. The anemometer contains two microswitches that close as the top rotates, each rotation triggers both switches. You will also find an RJ11 Breakout Board which will allow you to connect it to the breadboard. - -1. Interface this to your ESP8266 using the `G` (ground) pin and `D7` (GPIO13) pins. -2. Modify the code above to record how many rotations the anemometer makes. - -## 2 Timer Interupts - -A timer interrupt triggers an ISR at a predetermined time interval. Whilst it is possible to write code to interact directly with `Timer0` it is much easier to use the `Ticker` library. - -```cpp -#include -#define LED 2 -Ticker blinker; - -void setup() { - Serial.begin(9600); - Serial.println(""); - pinMode(LED,OUTPUT); - blinker.attach(2, changeState); -} - -void changeState() { - //Invert Current State of LED - digitalWrite(LED, !(digitalRead(LED))); -} - -void loop() {} -``` - -### 2.2 Test Your Understanding - -1. Modify the code from the previous step to reset the counter every 5 seconds. -2. Just before you reset the counter, store the current value in a variable. -3. Use the handheld digital anemometer to calibrate your system in MPH. - -## Fritzing Files - -[ESP8266 Development Board](https://github.com/squix78/esp8266-fritzing-parts/blob/master/nodemcu-v1.0/NodeMCUV1.0.fzpz). - -## References - -Interrupt example with thanks to [Tech Tutorials X](https://techtutorialsx.com/2016/12/11/esp8266-external-interrupts/) - -Ticker example with thanks to [Circuits For You](https://circuits4you.com/2018/01/02/esp8266-timer-ticker-example/) diff --git a/exercises/MQTT/arduino/samples/08 Networking.md b/exercises/MQTT/arduino/samples/08 Networking.md deleted file mode 100644 index 1b5e218..0000000 --- a/exercises/MQTT/arduino/samples/08 Networking.md +++ /dev/null @@ -1,85 +0,0 @@ - -# Networking - -In this worksheet we will expore how to connect to the internet and how to publish data to an MQTT broker. - -You will need to install additional libraries (Sketch > Include Library > Manage Libraries). - -Search for the the **pubsubclient** library and install the latest version. - -The following code will allow you NodeMCU (ESP8266) to connect to a network. Make sure you enter the ssid for your access point along with the correct password. This script will connect the microcontroller to your chosen access point and print the IP address to the _Serial Monitor_. - -```cpp -#include "ESP8266WiFi.h" - -const char* ssid = "XXX"; -const char* password = "XXX"; - -void setup() { - Serial.begin(9600); - WiFi.begin(ssid, password); - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); - } - Serial.println(""); - Serial.println("WiFi connected"); - Serial.println(WiFi.localIP()); -} - -void loop() { - -} -``` - -## Using the University Network - -This script won't be able to connect you to a network requiring a username and password (such as your University network). In this situation you will need to connect to a special network that has been set up for IoT projects. Typically this will have its access restricted to the standard MQTT ports (1883 for MQTT traffic and 8883 for using MQTT over SSL). - -At Coventry University you should connect use the ssid `ECL-LEGO-ROBOTS` with the password `9cjjp64270`. - -## Using Smartphone Tethering - -If you are not in range of a suitable wifi network you should be able to use your phone's data connection. Since the amount of data being transmittedis very small this should not have much impact on your data usage. - -## Using the Network Time Protocol (NTP) - -NTP is a networking protocol to synchronise clocks over a network that has varying latency (such as the Internet). It is designed to synchronise the computers to within a few milliseconds of UTC. It uses UDP rather than TCP as its protocol. It works over port 123. - -This is a very useful protocol as it allows you to timestamp your data without needing to use a Real Time Clock (RTC). It can also be used to correctly initialise an RTC when the microcontroller is first started. - -```cpp -#include -#include -#include - -const char *ssid = "ECL-LEGO-ROBOTS"; -const char *password = "9cjjp64270"; - -WiFiUDP ntpUDP; -NTPClient timeClient(ntpUDP); - -void setup(){ - Serial.begin(9600); - - WiFi.begin(ssid, password); - - while ( WiFi.status() != WL_CONNECTED ) { - delay ( 500 ); - Serial.print ( "." ); - } - - timeClient.begin(); -} - -void loop() { - timeClient.update(); - - Serial.println(timeClient.getFormattedTime()); - Serial.println(timeClient.getEpochTime()); - - delay(1000); -} -``` - -// https://github.com/arduino-libraries/NTPClient/blob/master/NTPClient.h diff --git a/exercises/MQTT/arduino/samples/09 Publishing Data.md b/exercises/MQTT/arduino/samples/09 Publishing Data.md deleted file mode 100644 index e69de29..0000000 diff --git a/exercises/MQTT/arduino/samples/gallery.md b/exercises/MQTT/arduino/samples/gallery.md deleted file mode 100644 index 582a8c5..0000000 --- a/exercises/MQTT/arduino/samples/gallery.md +++ /dev/null @@ -1,33 +0,0 @@ - -# Component Gallery - -Use the following to help identify your components: - -| Component | Code | Picture | -| ---------- | -------- | --------------------------------------------------- | -| NODEMCU v2 | ESP8266 | ![ADXL335](../../.images/components/NODEMCU-V2.jpg) | -| NODEMCU v3 | ESP8266 | ![ADXL335](../../.images/components/NODEMCU-V3.jpg) | -| ESP32 OLED | ESP32 | ![ADXL335](../../.images/components/esp32oled.png) | - -## Sensors and Actuators - -| Component | Code | Bus | Picture | -| ------------------ | -------- | ------ | --------------------------------------------------- | -| Tilt | ADXL335 | ANALOG | ![ADXL335](../../.images/components/ADXL335.jpg) | -| Sound | - | ANALOG | ![ADXL335](../../.images/components/SOUND.jpg) | -| CO2 Gas Sensor | MQ-135 | ANALOG | ![ADXL335](../../.images/components/MQ-135.jpg) | -| Temp/Humidity | DHT11 | SERIAL | ![ADXL335](../../.images/components/DHT11.jpg) | -| GPS | NEO-6M | SERIAL | ![ADXL335](../../.images/components/NEO-6M.jpg) | -| Nokia 5110 Screen | PCD8544 | SERIAL | ![ADXL335](../../.images/components/NOKIA-5110.jpg) | -| Air Pressure | BMP10 | I2C | ![ADXL335](../../.images/components/BMP10.jpg) | -| Compass | HMC5883L | I2C | ![ADXL335](../../.images/components/HMC5883L.jpg) | -| OLED Screen | SSD1306 | I2C | ![ADXL335](../../.images/components/LANMU.jpg) | -| Light | TSL2561 | I2C | ![ADXL335](../../.images/components/TSL2561.jpg) | -| UV | VEML6070 | I2C | ![ADXL335](../../.images/components/VEML6070.jpg) | -| Temp (water) | DS18B20 | 1-Wire | ![ADXL335](../../.images/components/DS18B20.jpg) | -| Analog Multiplexer | MCP3008 | SPI | ![ADXL335](../../.images/components/MCP3008.jpg) | -| 3 Axis Gyro/Accel | MPU5060 | SPI | ![MPU5060](../../.images/components/MPU5060.png) | -| 9-axis high pressure attitude | MPU9151 | SPI | ![MPU9151](../../.images/components/MPU9151.png) | -| GPS | NEO-7M | SERIAL | ![NEO-7M](../../.images/components/NEO-7M.png) | -| Servo Driver Board | xxx | I2C | ![NEO-7M](../../.images/components/servo-driver.png) | -| Servo | SG90 | PWM | ![NEO-7M](../../.images/components/servo.png) | diff --git a/exercises/MQTT/arduino/samples/sample_sketches/DHT11.ino b/exercises/MQTT/arduino/samples/sample_sketches/DHT11.ino deleted file mode 100644 index 983ae05..0000000 --- a/exercises/MQTT/arduino/samples/sample_sketches/DHT11.ino +++ /dev/null @@ -1,23 +0,0 @@ - -#include -#include -#include - -DHT_Unified dht(D4, DHT11); - -void setup() { - Serial.begin(9600); - dht.begin(); -} - -void loop() { - delay(5000); - sensors_event_t event; - dht.temperature().getEvent(&event); - if (!isnan(event.temperature)) { - Serial.print("Temperature: "); - Serial.print(event.temperature); - Serial.println(" *C"); - } -} - diff --git a/exercises/MQTT/arduino/samples/sample_sketches/TLS2561.ino b/exercises/MQTT/arduino/samples/sample_sketches/TLS2561.ino deleted file mode 100644 index 0d03a9b..0000000 --- a/exercises/MQTT/arduino/samples/sample_sketches/TLS2561.ino +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include - -SFE_TSL2561 light; - -boolean gain; -unsigned int ms; - -void setup() { - Serial.begin(9600); - Serial.println("TSL2561 example sketch"); - light.begin(); - unsigned char ID; - if (light.getID(ID)) { - Serial.print("Got factory ID: 0X"); - Serial.print(ID,HEX); - Serial.println(", should be 0X5X"); - } else { - byte error = light.getError(); - printError(error); - } - gain = 0; - unsigned char time = 2; - Serial.println("Set timing..."); - light.setTiming(gain,time,ms); - Serial.println("Powerup..."); - light.setPowerUp(); -} - -void loop() { - delay(ms); - unsigned int data0, data1; - if ( light.getData(data0,data1) ) { - Serial.print("data0: "); - Serial.print(data0); - Serial.print(" data1: "); - Serial.print(data1); - double lux; - boolean good; - good = light.getLux(gain,ms,data0,data1,lux); - Serial.print(" lux: "); - Serial.print(lux); - if (good) Serial.println(" (good)"); else Serial.println(" (BAD)"); - } else { - byte error = light.getError(); - printError(error); - } -} - -void printError(byte error) { - Serial.print("I2C error: "); - Serial.print(error,DEC); - Serial.print(", "); - switch(error) { - case 0: - Serial.println("success"); - break; - case 1: - Serial.println("data too long for transmit buffer"); - break; - case 2: - Serial.println("received NACK on address (disconnected?)"); - break; - case 3: - Serial.println("received NACK on data"); - break; - case 4: - Serial.println("other error"); - break; - default: - Serial.println("unknown error"); - } -} diff --git a/exercises/MQTT/arduino/samples/sample_sketches/adafruit_dht11.ino b/exercises/MQTT/arduino/samples/sample_sketches/adafruit_dht11.ino deleted file mode 100644 index a553971..0000000 --- a/exercises/MQTT/arduino/samples/sample_sketches/adafruit_dht11.ino +++ /dev/null @@ -1,80 +0,0 @@ - -#include -#include "Adafruit_MQTT.h" -#include "Adafruit_MQTT_Client.h" - -#include -#include -#include - -DHT_Unified dht(D4, DHT11); - -#define WLAN_SSID "ECL-LEGO-ROBOTS" -#define WLAN_PASS "9cjjp64270" -#define AIO_SERVER "io.adafruit.com" -#define AIO_SERVERPORT 1883 -#define AIO_USERNAME "xxxxxxxxx" -#define AIO_KEY "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - -WiFiClient client; -Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY); -Adafruit_MQTT_Publish temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/temperature"); - -uint32_t temp=0; - -void setup(void) { - Serial.begin(9600); - dht.begin(); - pinMode(2, OUTPUT); - WiFi.begin(WLAN_SSID, WLAN_PASS); - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); - } - Serial.println(); - - Serial.println("WiFi connected"); - Serial.println("IP address: "); Serial.println(WiFi.localIP()); -} - -void loop() { - delay(5000); - sensors_event_t event; - dht.temperature().getEvent(&event); - if (isnan(event.temperature)) { - Serial.println("Error reading temperature!"); - } else { - Serial.print("Temperature: "); - Serial.print(event.temperature); - Serial.println(" *C"); - MQTT_connect(); - if (!temperature.publish(event.temperature)) { - Serial.println("Failed"); - } - } -} - -void MQTT_connect() { - int8_t ret; - - // Stop if already connected. - if (mqtt.connected()) { - return; - } - - Serial.print("Connecting to MQTT... "); - - uint8_t retries = 3; - while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected - Serial.println(mqtt.connectErrorString(ret)); - Serial.println("Retrying MQTT connection in 5 seconds..."); - mqtt.disconnect(); - delay(5000); // wait 5 seconds - retries--; - if (retries == 0) { - // basically die and wait for WDT to reset me - while (1); - } - } - Serial.println("MQTT Connected!"); -} diff --git a/exercises/MQTT/arduino/samples/sample_sketches/dht11_deepsleep.ino b/exercises/MQTT/arduino/samples/sample_sketches/dht11_deepsleep.ino deleted file mode 100644 index 41c732e..0000000 --- a/exercises/MQTT/arduino/samples/sample_sketches/dht11_deepsleep.ino +++ /dev/null @@ -1,84 +0,0 @@ - -#include -#include "Adafruit_MQTT.h" -#include "Adafruit_MQTT_Client.h" - -#include -#include -#include - -DHT_Unified dht(D4, DHT11); - -#define WLAN_SSID "ECL-LEGO-ROBOTS" -#define WLAN_PASS "9cjjp64270" -#define AIO_SERVER "io.adafruit.com" -#define AIO_SERVERPORT 1883 -#define AIO_USERNAME "xxxxxxxx" -#define AIO_KEY "xxxxxxxx" - -WiFiClient client; -Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY); -Adafruit_MQTT_Publish temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/temperature"); -Adafruit_MQTT_Publish humidity = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/humidity"); - -uint32_t temp=0; -const int sleepMin = 10; - -void setup(void) { - Serial.begin(9600); - dht.begin(); - pinMode(2, OUTPUT); - WiFi.begin(WLAN_SSID, WLAN_PASS); - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); - } - Serial.println("IP address: "); Serial.println(WiFi.localIP()); - delay(5000); - sensors_event_t event; - dht.temperature().getEvent(&event); - if (isnan(event.temperature)) { - Serial.println("Error reading temperature!"); - } else { - Serial.print("Temperature: "); - Serial.print(event.temperature); - Serial.println(" *C"); - MQTT_connect(); - if (!temperature.publish(event.temperature)) { - Serial.println("Failed to publish temperature"); - } - } - delay(5000); - Serial.println("ESP8266 going into deep sleep mode"); - ESP.deepSleep(560e6); // 56e6 is 56 seconds -} - -void loop() { - -} - -void MQTT_connect() { - int8_t ret; - - // Stop if already connected. - if (mqtt.connected()) { - return; - } - - Serial.print("Connecting to MQTT... "); - - uint8_t retries = 3; - while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected - Serial.println(mqtt.connectErrorString(ret)); - Serial.println("Retrying MQTT connection in 5 seconds..."); - mqtt.disconnect(); - delay(5000); // wait 5 seconds - retries--; - if (retries == 0) { - // basically die and wait for WDT to reset me - while (1); - } - } - Serial.println("MQTT Connected!"); -} - diff --git a/exercises/MQTT/arduino/samples/sample_sketches/sd_card.ino b/exercises/MQTT/arduino/samples/sample_sketches/sd_card.ino deleted file mode 100644 index f65e604..0000000 --- a/exercises/MQTT/arduino/samples/sample_sketches/sd_card.ino +++ /dev/null @@ -1,79 +0,0 @@ -/* - SD card read/write - - This example shows how to read and write data to and from an SD card file - The circuit: - * SD card attached to SPI bus as follows: - ** MOSI - D7 - ** MISO - D6 - ** CLK - D5 - ** CS - D8 - - created Nov 2010 - by David A. Mellis - modified 9 Apr 2012 - by Tom Igoe - modified 26 Apr 2018 - by David Croft - - This example code is in the public domain. - - */ - -#include -#include - -File myFile; - -void setup() { - // Open serial communications and wait for port to open: - Serial.begin(9600); - while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only - } - - - Serial.print("Initializing SD card..."); - - if (!SD.begin(D8)) { - Serial.println("initialization failed!"); - while (1); - } - Serial.println("initialization done."); - - // open the file. note that only one file can be open at a time, - // so you have to close this one before opening another. - myFile = SD.open("test.txt", FILE_WRITE); - - // if the file opened okay, write to it: - if (myFile) { - Serial.print("Writing to test.txt..."); - myFile.println("testing 1, 2, 3, 42."); - // close the file: - myFile.close(); - Serial.println("done."); - } else { - // if the file didn't open, print an error: - Serial.println("error opening test.txt"); - } - - // re-open the file for reading: - myFile = SD.open("test.txt"); - if (myFile) { - Serial.println("test.txt:"); - - // read from the file until there's nothing else in it: - while (myFile.available()) { - Serial.write(myFile.read()); - } - // close the file: - myFile.close(); - } else { - // if the file didn't open, print an error: - Serial.println("error opening test.txt"); - } -} - -void loop() { - // nothing happens after setup -} diff --git a/exercises/MQTT/arduino/screen/include/readme.txt b/exercises/MQTT/arduino/screen/include/readme.txt deleted file mode 100644 index 194dcd4..0000000 --- a/exercises/MQTT/arduino/screen/include/readme.txt +++ /dev/null @@ -1,39 +0,0 @@ - -This directory is intended for project header files. - -A header file is a file containing C declarations and macro definitions -to be shared between several project source files. You request the use of a -header file in your project source file (C, C++, etc) located in `src` folder -by including it, with the C preprocessing directive `#include'. - -```src/main.c - -#include "header.h" - -int main (void) -{ - ... -} -``` - -Including a header file produces the same results as copying the header file -into each source file that needs it. Such copying would be time-consuming -and error-prone. With a header file, the related declarations appear -in only one place. If they need to be changed, they can be changed in one -place, and programs that include the header file will automatically use the -new version when next recompiled. The header file eliminates the labor of -finding and changing all the copies as well as the risk that a failure to -find one copy will result in inconsistencies within a program. - -In C, the usual convention is to give header files names that end with `.h'. -It is most portable to use only letters, digits, dashes, and underscores in -header file names, and at most one dot. - -Read more about using header files in official GCC documentation: - -* Include Syntax -* Include Operation -* Once-Only Headers -* Computed Includes - -https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/exercises/MQTT/arduino/screen/lib/readme.txt b/exercises/MQTT/arduino/screen/lib/readme.txt deleted file mode 100644 index cfa16df..0000000 --- a/exercises/MQTT/arduino/screen/lib/readme.txt +++ /dev/null @@ -1,41 +0,0 @@ - -This directory is intended for project specific (private) libraries. -PlatformIO will compile them to static libraries and link them to executable files. - -The source code of each library should be placed in separate directories, like -"lib/private_lib/[here are source files]". - -For example, see the structure of the following two libraries `Foo` and `Bar`: - -|--lib -| | -| |--Bar -| | |--docs -| | |--examples -| | |--src -| | |- Bar.c -| | |- Bar.h -| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html -| | -| |--Foo -| | |- Foo.c -| | |- Foo.h -| | -| |- readme.txt --> THIS FILE -| -|- platformio.ini -|--src - |- main.c - -Then in `src/main.c` you should use: - -#include -#include - -// rest H/C/CPP code - -PlatformIO will find your libraries automatically, configure preprocessor's -include paths and build them. - -More information about PlatformIO Library Dependency Finder -- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/exercises/MQTT/arduino/screen/platformio.ini b/exercises/MQTT/arduino/screen/platformio.ini deleted file mode 100644 index ef7048d..0000000 --- a/exercises/MQTT/arduino/screen/platformio.ini +++ /dev/null @@ -1,20 +0,0 @@ -; PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html - -[env:lolin32] -platform = espressif32 -board = lolin32 -framework = arduino -; upload_port = /dev/ttyUSB0 -upload_speed = 9600 ; 9600 14400 19200 28800 38400 57600 115200 -upload_protocol = esptool - -lib_deps = - ESP8266_SSD1306 diff --git a/exercises/MQTT/arduino/screen/src/main.cpp b/exercises/MQTT/arduino/screen/src/main.cpp deleted file mode 100644 index f437a30..0000000 --- a/exercises/MQTT/arduino/screen/src/main.cpp +++ /dev/null @@ -1,24 +0,0 @@ - -#include -#include "SSD1306.h" - -SSD1306 display(0x3c, 5, 4); // I2C: pin 5 is data, 4 is clock - -int sensorValue = 0; - -void setup() { - display.init(); - - display.flipScreenVertically(); - display.setFont(ArialMT_Plain_10); - display.setTextAlignment(TEXT_ALIGN_LEFT); -} - -void loop() { - sensorValue = analogRead(2); // GPIO pin 2 (change to D4 for ESP8266) - Serial.println(sensorValue); - display.clear(); - display.drawString(0, 0, "Hello world: " + String(millis())); - display.display(); - delay(10); -} diff --git a/exercises/MQTT/nodejs/index.js b/exercises/MQTT/nodejs/index.js deleted file mode 100755 index d61e082..0000000 --- a/exercises/MQTT/nodejs/index.js +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env node - -'use strict' - -const fs = require('fs') -const mqtt = require('mqtt') - -const CAfile = [fs.readFileSync('mqtt.crt')] - -const options = { - host: 'mqtt.coventry.ac.uk', - port: 8883, - protocol: 'mqtts', - protocolId: 'MQIsdp', - ca: CAfile, - username: 'xxx', - password: 'xxx', - secureProtocol: 'TLSv1_method', - protocolVersion: 3 -} - -const client = mqtt.connect(options) - -client.on('connect', () => { - console.log('connected') - client.subscribe('xxx/hello') -}) - -// receives MQTT message (subscribe) -client.on('message', (topic, message) => console.log(`received topic: ${topic}, message: ${message}`)) - -client.publish('xxx/hello', 'Hello World!') diff --git a/exercises/MQTT/nodejs/mqtt.crt b/exercises/MQTT/nodejs/mqtt.crt deleted file mode 100644 index d30f409..0000000 --- a/exercises/MQTT/nodejs/mqtt.crt +++ /dev/null @@ -1,31 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIFYDCCA0igAwIBAgIURFc0JFuBiZs18s64KztbpybwdSgwDQYJKoZIhvcNAQEL -BQAwSDELMAkGA1UEBhMCQk0xGTAXBgNVBAoTEFF1b1ZhZGlzIExpbWl0ZWQxHjAc -BgNVBAMTFVF1b1ZhZGlzIFJvb3QgQ0EgMiBHMzAeFw0xMjAxMTIxODU5MzJaFw00 -MjAxMTIxODU5MzJaMEgxCzAJBgNVBAYTAkJNMRkwFwYDVQQKExBRdW9WYWRpcyBM -aW1pdGVkMR4wHAYDVQQDExVRdW9WYWRpcyBSb290IENBIDIgRzMwggIiMA0GCSqG -SIb3DQEBAQUAA4ICDwAwggIKAoICAQChriWyARjcV4g/Ruv5r+LrI3HimtFhZiFf -qq8nUeVuGxbULX1QsFN3vXg6YOJkApt8hpvWGo6t/x8Vf9WVHhLL5hSEBMHfNrMW -n4rjyduYNM7YMxcoRvynyfDStNVNCXJJ+fKH46nafaF9a7I6JaltUkSs+L5u+9ym -c5GQYaYDFCDy54ejiK2toIz/pgslUiXnFgHVy7g1gQyjO/Dh4fxaXc6AcW34Sas+ -O7q414AB+6XrW7PFXmAqMaCvN+ggOp+oMiwMzAkd056OXbxMmO7FGmh77FOm6RQ1 -o9/NgJ8MSPsc9PG/Srj61YxxSscfrf5BmrODXfKEVu+lV0POKa2Mq1W/xPtbAd0j -IaFYAI7D0GoT7RPjEiuA3GfmlbLNHiJuKvhB1PLKFAeNilUSxmn1uIZoL1NesNKq -IcGY5jDjZ1XHm26sGahVpkUG0CM62+tlXSoREfA7T8pt9DTEceT/AFr2XK4jYIVz -8eQQsSWu1ZK7E8EM4DnatDlXtas1qnIhO4M15zHfeiFuuDIIfR0ykRVKYnLP43eh -vNURG3YBZwjgQQvD6xVu+KQZ2aKrr+InUlYrAoosFCT5v0ICvybIxo/gbjh9Uy3l -7ZizlWNof/k19N+IxWA1ksB8aRxhlRbQ694Lrz4EEEVlWFA4r0jyWbYW8jwNkALG -cC4BrTwV1wIDAQABo0IwQDAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIB -BjAdBgNVHQ4EFgQU7edvdlq/YOxJW8ald7tyFnGbxD0wDQYJKoZIhvcNAQELBQAD -ggIBAJHfgD9DCX5xwvfrs4iP4VGyvD11+ShdyLyZm3tdquXK4Qr36LLTn91nMX66 -AarHakE7kNQIXLJgapDwyM4DYvmL7ftuKtwGTTwpD4kWilhMSA/ohGHqPHKmd+RC -roijQ1h5fq7KpVMNqT1wvSAZYaRsOPxDMuHBR//47PERIjKWnML2W2mWeyAMQ0Ga -W/ZZGYjeVYg3UQt4XAoeo0L9x52ID8DyeAIkVJOviYeIyUqAHerQbj5hLja7NQ4n -lv1mNDthcnPxFlxHBlRJAHpYErAK74X9sbgzdWqTHBLmYF5vHX/JHyPLhGGfHoJE -+V+tYlUkmlKY7VHnoX6XOuYvHxHaU4AshZ6rNRDbIl9qxV6XU/IyAgkwo1jwDQHV -csaxfGl7w/U2Rcxhbl5MlMVerugOXou/983g7aEOGzPuVBj+D77vfoRrQ+NwmNtd -dbINWQeFFSM51vHfqSYP1kjHs6Yi9TM3WpVHn3u6GBVv/9YUZINJ0gpnIdsPNWNg -KCLjsZWDzYWm3S8P52dSbrsvhXz1SnPnxT7AvSESBT/8twNJAlvIJebiVDj1eYeM -HVOyToV7BjjHLPj4sHKNJeV3UvQDHEimUF+IIDBu8oJDqz2XhOdT+yHBTw8imoa4 -WSr2Rz0ZiC3oheGe7IUIarFsNMkd7EgrO3jtZsSOeWmD3n+M ------END CERTIFICATE----- diff --git a/exercises/MQTT/nodejs/package.json b/exercises/MQTT/nodejs/package.json deleted file mode 100644 index 5d5ba6c..0000000 --- a/exercises/MQTT/nodejs/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "scanner", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "", - "license": "ISC", - "dependencies": { - "mqtt": "^2.18.8", - "noble": "^1.9.1", - "node-beacon-scanner": "^0.1.1" - } -} diff --git a/exercises/MQTT/python/coventry_pub.py b/exercises/MQTT/python/coventry_pub.py deleted file mode 100644 index 80630ea..0000000 --- a/exercises/MQTT/python/coventry_pub.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python - -import paho.mqtt.client as mqtt #import the client -import time -def on_connect(client, userdata, flags, rc): - if rc==0: - client.connected_flag=True #set flag - print("connected OK") - else: - print("Bad connection Returned code=",rc) -mqtt.Client.connected_flag=False #create flag in class -broker="mqtt.coventry.ac.uk" -client = mqtt.Client("python") -client.username_pw_set("302CEM", "xxx") -client.tls_set("./mqtt.crt") -client.on_connect=on_connect -client.loop_start() -print("Connecting to broker ",broker) -client.connect(broker, 8883) -while not client.connected_flag: #wait in loop - print("In wait loop") - time.sleep(1) -print("in Main Loop") -client.publish("powerx/hello", "Hello World", qos=0, retain=False) -client.loop_stop() # Stop loop -client.disconnect() # disconnect diff --git a/exercises/MQTT/python/publish_sockets.py b/exercises/MQTT/python/publish_sockets.py deleted file mode 100644 index d8d5b1b..0000000 --- a/exercises/MQTT/python/publish_sockets.py +++ /dev/null @@ -1,40 +0,0 @@ -#Note demo scripts have limited or no error detection and use -#timers to wait for events. They assume everything works ok -#www.steves-internet-guide.com -#contact steve@steves-internet-guide.com -#uses websockets publish-subscribe and receive message -import paho.mqtt.client as paho -import time -broker="broker.mqttdashboard.com" -broker="iot.eclipse.org" -broker="192.168.1.206" -#port= 80 -#port=1883 -port= 9001 -sub_topic="house/#" -def on_subscribe(client, userdata, mid, granted_qos): #create function for callback - print("subscribed with qos",granted_qos, "\n") - pass -def on_message(client, userdata, message): - print("message received " ,str(message.payload.decode("utf-8"))) -def on_publish(client,userdata,mid): #create function for callback - print("data published mid=",mid, "\n") - pass -def on_disconnect(client, userdata, rc): - print("client disconnected ok") -client= paho.Client("client-socks",transport='websockets') #create client object -#client= paho.Client("control1") -client.on_subscribe = on_subscribe #assign function to callback -client.on_publish = on_publish #assign function to callback -client.on_message = on_message #assign function to callback -client.on_disconnect = on_disconnect -print("connecting to broker ",broker,"on port ",port) -client.connect(broker,port) #establish connection -client.loop_start() -print("subscribing to ",sub_topic) -client.subscribe(sub_topic) -time.sleep(3) -client.publish("house/bulb1","on") #publish -time.sleep(4) - -client.disconnect() diff --git a/exercises/MQTT/raspberry_pi/install.sh b/exercises/MQTT/raspberry_pi/install.sh deleted file mode 100644 index 52b7a8b..0000000 --- a/exercises/MQTT/raspberry_pi/install.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -apt update -apt list --upgradable -# apt-get dist-upgrade DON'T RUN THIS!!! -apt upgrade -y -apt install -y apt-utils raspi-config - -# apt upgrade is still prompting to continue -# apt update && apt-get dist-upgrade && apt upgrade -y && apt install -y apt-utils raspi-config - -## remember to enable ssh!!!! - -raspi-config nonint do_expand_rootfs -partprobe -# raspi-config nonint do_ssh 0 -# sudo raspi-config nonint do_i2c 0 -apt install -y apt-transport-https rsync sudo nano git tree curl mc libssl-dev libffi-dev i2c-tools -raspi-config nonint do_hostname elephant -useradd -m -d /home/userx -s /bin/bash -c "userx account" userx -usermod -aG sudo userx -echo 'userx:mysecurepw'|chpasswd -echo 'root:mysecurepw'|chpasswd - -echo "KERNEL==\"i2c-0\" , GROUP=\"i2c\", MODE=\"0660\\n" -KERNEL==\"i2c-[1-9]*\", GROUP=\"i2c\", MODE=\"0666\"" > 'nano /lib/udev/rules.d/60-i2c-tools.rules' \ No newline at end of file diff --git a/exercises/MQTT/web_client/chat/index.html b/exercises/MQTT/web_client/chat/index.html deleted file mode 100644 index 89fc05f..0000000 --- a/exercises/MQTT/web_client/chat/index.html +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - Simple MQTT Client - - - - - - - -

Simple MQTT Client

-
- - - diff --git a/exercises/MQTT/web_client/chat/module.js b/exercises/MQTT/web_client/chat/module.js deleted file mode 100644 index 947f4c7..0000000 --- a/exercises/MQTT/web_client/chat/module.js +++ /dev/null @@ -1,33 +0,0 @@ - -'use strict' - -/* eslint no-unused-vars: 0 */ - -const messages = ( function() { - let msgs = [] - return { - extractData: payloadString => { - return payloadString - }, - add: data => { - if(data === '') throw new Error('empty string parameter') - msgs[0] = data - }, - get html() { - let html = '' - for(const msg of msgs) { - html += `

${msg}

` - } - return html - }, - get all() { - return msgs - }, - get count() { - return msgs.length - }, - clear: () => { - msgs = [] - } - } -})() diff --git a/exercises/MQTT/web_client/chat/mqtt.js b/exercises/MQTT/web_client/chat/mqtt.js deleted file mode 100644 index 4aedff6..0000000 --- a/exercises/MQTT/web_client/chat/mqtt.js +++ /dev/null @@ -1,51 +0,0 @@ - -'use strict' - -/* eslint no-undef: 0, no-magic-numbers: 0 */ - -const client = new Messaging.Client('broker.mqttdashboard.com', 8000, `myclientid_${parseInt(Math.random() * 100, 10)}`) - -client.onConnectionLost = responseObject => console.log(`connection lost: ${responseObject.errorMessage}`) -client.onMessageArrived = message => { - console.log(message) - console.log(`Topic: ${message.destinationName} Payload: ${message.payloadString}`) - try { - const msg = messages.extractData(message.payloadString) - messages.add(msg) - document.querySelector('div').innerHTML = messages.html - } catch(err) { - console.log(err.message) - } -} - -const publish = (payload, topic, qos) => { - const message = new Messaging.Message(payload) - message.destinationName = topic - message.qos = qos - client.send(message) -} - -const options = { - timeout: 3, - onSuccess: () => { - console.log('connected') - client.subscribe('cu/#', {qos: 2}) - console.log('Subscribed') - }, - onFailure: message => console.log(`Connection failed: ${message.errorMessage}`) -} - -client.connect(options) - -document.addEventListener('DOMContentLoaded', () => { - console.log('page loaded') - document.querySelector('input').onkeyup = e => { - console.log('keyup') - if(e.which === 13) { - console.log('enter key pressed') - const payload = document.querySelector('input').value - publish(payload,'cu/chat',2) - document.querySelector('input').value = '' - } - } -}) diff --git a/exercises/MQTT/web_client/chat/test/module.test.js b/exercises/MQTT/web_client/chat/test/module.test.js deleted file mode 100644 index 419a72e..0000000 --- a/exercises/MQTT/web_client/chat/test/module.test.js +++ /dev/null @@ -1,134 +0,0 @@ - -'use strict' - -/* eslint no-undef: 0 */ - -describe('check encapsulation', () => { - it('check message array is private', () => { - try { - const data = msgs - expect(1).toBe(0) // this line should not be run! - console.log(data) - } catch(err) { - expect(err.message).toBe('Can\'t find variable: msgs') - } - }) -}) - -describe('properties', () => { - - describe('html', () => { - - beforeEach( () => messages.clear()) - - it('when adding a single message', () => { - messages.add('hello world') - const html = messages.html - expect(html).toBe('

hello world

') - }) - - it('when adding multiple messages', () => { - messages.add('hello') - messages.add('goodbye') - const html = messages.html - expect(html).toBe('

goodbye

') - }) - - }) - - describe('all', () => { - - beforeEach( () => messages.clear()) - - it('when adding a single message', () => { - messages.add('hello world') - const msgs = messages.all - expect(Array.isArray(msgs)).toBeTruthy() - expect(msgs.length).toBe(1) - }) - - it('when adding multiple messages', () => { - messages.add('hello') - messages.add('goodbye') - const msgs = messages.all - expect(Array.isArray(msgs)).toBeTruthy() - expect(msgs.length).toBe(1) - }) - - }) - - describe('count', () => { - - it('when adding a single message', () => { - messages.add('hello world') - expect(messages.count).toBe(1) - }) - - it('when adding multiple messages', () => { - messages.add('hello') - messages.add('goodbye') - expect(messages.count).toBe(1) - }) - - }) - -}) - -describe('methods', () => { - describe('extractData', () => { - - it('returns the message', () => { - const msg = messages.extractData('Hello World') - expect(msg).toBe('Hello World') - }) - - }) - - describe('addMessage', () => { - - beforeEach( () => messages.clear()) - - it('add a single message', () => { - messages.add('hello world') - expect(messages.count).toBe(1) - const msgs = messages.all - expect(msgs[0]).toBe('hello world') - }) - - it('adding multiple messages', () => { - messages.add('hello') - messages.add('goodbye') - expect(messages.count).toBe(1) - const msgs = messages.all - expect(msgs[0]).toBe('goodbye') - }) - - it('adding an empty message should throw an error', () => { - try { - messages.add('') - expect(1).toBe(0) // this line should not be run! - } catch(err) { - expect(err.message).toBe('empty string parameter') - } - }) - - }) - - describe('clear', () => { - - it('clearing a single message', () => { - messages.add('hello world') - messages.clear() - expect(messages.count).toBe(0) - }) - - it('clearing multiple messages', () => { - messages.add('hello') - messages.add('goodbye') - messages.clear() - expect(messages.count).toBe(0) - }) - - }) - -}) diff --git a/exercises/MQTT/web_client/chat/test/testrunner.html b/exercises/MQTT/web_client/chat/test/testrunner.html deleted file mode 100644 index 02d8362..0000000 --- a/exercises/MQTT/web_client/chat/test/testrunner.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - Running Jasmine tests in the browser - - - - - - - - - - - - - diff --git a/exercises/MQTT/web_client/map/index.html b/exercises/MQTT/web_client/map/index.html deleted file mode 100644 index e6fac7a..0000000 --- a/exercises/MQTT/web_client/map/index.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - -
- - - diff --git a/exercises/MQTT/web_client/map/map.js b/exercises/MQTT/web_client/map/map.js deleted file mode 100644 index 7bd1c03..0000000 --- a/exercises/MQTT/web_client/map/map.js +++ /dev/null @@ -1,46 +0,0 @@ - -'use strict' - -let map - -function loadMap() { - const mapOptions = { - center:new google.maps.LatLng(52.4080, -1.5104), - zoom:12, - mapTypeId:google.maps.MapTypeId.ROADMAP - } - map = new google.maps.Map(document.getElementById('sample'),mapOptions) - if (navigator.geolocation) { - navigator.geolocation.getCurrentPosition( position => { - console.log(`current location: ${position.coords.latitude}, ${position.coords.longitude}`) - map.setCenter(new google.maps.LatLng(position.coords.latitude, position.coords.longitude)) - }) - } -} - -google.maps.event.addDomListener(window, 'load', loadMap) - -// ------- MQTT STUFF - -const client = new Messaging.Client('broker.mqttdashboard.com', 8000, `myclientid_${parseInt(Math.random() * 100, 10)}`) - -client.onConnectionLost = responseObject => console.log(`connection lost: ${responseObject.errorMessage}`) - -client.onMessageArrived = message => { - const data = maps.extractData(message.payloadString) - maps.addMarker(data) - maps.scale(map) - //scaleMap() -} - -const options = { - timeout: 3, - onSuccess: () => { - console.log('connected') - client.subscribe('cov/map', {qos: 2}) - console.log('Subscribed') - }, - onFailure: message => console.log(`Connection failed: ${message.errorMessage}`) -} - -client.connect(options) diff --git a/exercises/MQTT/web_client/map/module.js b/exercises/MQTT/web_client/map/module.js deleted file mode 100644 index 93c242e..0000000 --- a/exercises/MQTT/web_client/map/module.js +++ /dev/null @@ -1,46 +0,0 @@ - -'use strict' - -const maps = (function() { - - const markers = [] - - return { - extractData: payloadString => { - try { - const data = JSON.parse(payloadString) - return data - } catch(err) { - if(err.message === 'Unexpected token h in JSON at position 0') { - throw new Error('parameter is not a json string') - } - throw new Error(err) // we need to propagate all other errors - } - }, - addMarker: data => { - const latLng = new google.maps.LatLng(data.lat, data.lon) - const mkr = { position: latLng, title: data.label } - const marker = new google.maps.Marker(mkr) - markers.push(marker) - return marker - }, - get all() { - return markers - }, - scale: map => { - let bounds = new google.maps.LatLngBounds() - const markers = maps.all - for (var i = 0; i < markers.length; i++) { - markers[i].setMap(map) - bounds.extend(markers[i].getPosition()) - } - map.fitBounds(bounds) - console.log(`zoom level: ${map.getZoom()}`) - if(map.getZoom() > 16) map.setZoom(16) - const currentBounds = map.getBounds() - console.log(JSON.stringify(currentBounds, null, 2)) - return currentBounds - } - } - -})() diff --git a/exercises/MQTT/web_client/map/style.css b/exercises/MQTT/web_client/map/style.css deleted file mode 100644 index 7a7e164..0000000 --- a/exercises/MQTT/web_client/map/style.css +++ /dev/null @@ -1,5 +0,0 @@ - -#sample { - width:800px; - height:400px; -} diff --git a/exercises/MQTT/web_client/map/test/module.test.js b/exercises/MQTT/web_client/map/test/module.test.js deleted file mode 100644 index c95cff0..0000000 --- a/exercises/MQTT/web_client/map/test/module.test.js +++ /dev/null @@ -1,66 +0,0 @@ - -'use strict' - -/* eslint no-undef: 0 */ - -describe('check encapsulation', () => { - it('check markers array is private', () => { - try { - const data = markers - expect(1).toBe(0) // this line should not be run! - console.log(data) - } catch(err) { - expect(err.message).toBe('markers is not defined') - } - }) - - describe('properties', () => { - - describe('all', () => { - - it('check for an empty array', () => { - const pins = maps.all - console.log(pins) - expect(Array.isArray(pins)).toBeTruthy() - expect(pins.length).toBe(0) - }) - - }) - - }) - - describe('methods', () => { - - describe('extractData', () => { - - it('extracts complete data', () => { - const str = '{"lat": 52.4082, "lon": -1.5071, "label": "cathedral"}' - const data = maps.extractData(str) - expect(typeof data).toBe('object') - expect(Object.keys(data).length).toBe(3) - expect(data.lat).toBe(52.4082) - expect(data.lon).toBe(-1.5071) - expect(data.label).toBe('cathedral') - }) - - it('throw error if parameter is not a json string', () => { - try { - maps.extractData('hello world') - expect(0).toBe(1) - } catch(err) { - expect(err.message).toBe('parameter is not a json string') - } - }) - - }) - - describe('addMarker', () => { - - }) - - describe('scale', () => { - - }) - - }) -}) diff --git a/exercises/MQTT/web_client/map/test/testrunner.html b/exercises/MQTT/web_client/map/test/testrunner.html deleted file mode 100644 index 960a908..0000000 --- a/exercises/MQTT/web_client/map/test/testrunner.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - Running Jasmine tests in the browser - - - - - - - - - - - - - - diff --git a/exercises/MQTT/web_client/paho/index.html b/exercises/MQTT/web_client/paho/index.html deleted file mode 100644 index ca0d41d..0000000 --- a/exercises/MQTT/web_client/paho/index.html +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - Simple MQTT Client - - - - - - -

Simple MQTT Client

-
- - - diff --git a/exercises/MQTT/web_client/paho/websockets-1.htm b/exercises/MQTT/web_client/paho/websockets-1.htm deleted file mode 100644 index 5bf7668..0000000 --- a/exercises/MQTT/web_client/paho/websockets-1.htm +++ /dev/null @@ -1,42 +0,0 @@ - - - JavaScript MQTT WebSocket Example - - - - -

Main Body

- - - \ No newline at end of file diff --git a/exercises/MQTT/web_client/paho/websockets-2.htm b/exercises/MQTT/web_client/paho/websockets-2.htm deleted file mode 100644 index cbd80d7..0000000 --- a/exercises/MQTT/web_client/paho/websockets-2.htm +++ /dev/null @@ -1,57 +0,0 @@ - - - - JavaScript MQTT WebSocket Example - - - - -

Main Body

- - - \ No newline at end of file diff --git a/exercises/MQTT/web_client/paho/websockets-3.htm b/exercises/MQTT/web_client/paho/websockets-3.htm deleted file mode 100644 index f0f94c9..0000000 --- a/exercises/MQTT/web_client/paho/websockets-3.htm +++ /dev/null @@ -1,180 +0,0 @@ - - - - - - Websockets Using JavaScript MQTT Client - - - - - - - -

Websockets Using JavaScript MQTT Client

- - - - -
Connection Status: Not Connected
- -
-
- -Server:

-Port:

- -
-
-
-Subscribe Topic:

- - -
-
-
- -Message:

-Publish Topic:

- -
-Messages:

- - - diff --git a/exercises/MQTT/web_client/paho/websockets-4.htm b/exercises/MQTT/web_client/paho/websockets-4.htm deleted file mode 100644 index 933e50e..0000000 --- a/exercises/MQTT/web_client/paho/websockets-4.htm +++ /dev/null @@ -1,255 +0,0 @@ - - - - - - Websockets Using JavaScript MQTT Client - - - - - - - -

Websockets MQTT Monitor

- - - - -
Connection Status: Not Connected
- -
- - - - - - - -
- -
- -Server:

-Port:

-Clean Session:

-Username:

-Password:

- - -
-
-
-Subscribe Topic:
-Subscribe QOS:
- -
-
-
- -Message:

-Publish Topic:

-Publish QOS:
-Retain Message:
- -
-
-Status Messages: -
-
-Received Messages: - -
-
- - - diff --git a/exercises/MQTT/web_client/paho/websockets-ssl.htm b/exercises/MQTT/web_client/paho/websockets-ssl.htm deleted file mode 100644 index 8c59c9f..0000000 --- a/exercises/MQTT/web_client/paho/websockets-ssl.htm +++ /dev/null @@ -1,53 +0,0 @@ - - - JavaScript MQTT WebSocket Example - - - - -

Main Body

- - - \ No newline at end of file diff --git a/exercises/MQTT/web_client/websocket/index.html b/exercises/MQTT/web_client/websocket/index.html deleted file mode 100644 index 8c6a7a9..0000000 --- a/exercises/MQTT/web_client/websocket/index.html +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - The HTML5 Herald - - - - - - -

Simple Websocket Client

-
- - - - diff --git a/exercises/MQTT/web_client/websocket/index.js b/exercises/MQTT/web_client/websocket/index.js deleted file mode 100644 index b580d8c..0000000 --- a/exercises/MQTT/web_client/websocket/index.js +++ /dev/null @@ -1,24 +0,0 @@ - -'use strict' - -const Koa = require('koa'), - route = require('koa-route'), - websockify = require('koa-websocket') - -const app = websockify(new Koa()) - -app.ws.use((ctx, next) => next(ctx)) - -// Using routes -app.ws.use(route.all('/test/:id', ctx => { - console.log(`route triggered by id: ${ctx.params.id}`) - ctx.websocket.send('Hello World') - ctx.websocket.on('message', message => { - console.log('message received') - console.log(message) - ctx.websocket.send(`You Sent: ${message}`) - }) -})) - -app.listen(3000) - diff --git a/exercises/MQTT/web_client/websocket/package.json b/exercises/MQTT/web_client/websocket/package.json deleted file mode 100644 index e23c51f..0000000 --- a/exercises/MQTT/web_client/websocket/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "websocket", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "", - "license": "ISC", - "dependencies": { - "koa": "^2.7.0", - "koa-route": "^3.2.0", - "koa-websocket": "^5.0.1" - } -} diff --git a/exercises/Programming Digispark ATTiny85 board.md b/exercises/Programming Digispark ATTiny85 board.md deleted file mode 100644 index 93b736f..0000000 --- a/exercises/Programming Digispark ATTiny85 board.md +++ /dev/null @@ -1,64 +0,0 @@ -# Programming the Digispark ATTiny85 board. - -![Digispark ATTiny85](.images/DigisparkATtiny85.jpg) - -Step 1. Check you have installed the drivers from Digispark website. There are instructions and links to driver files here: -http://digistump.com/wiki/digispark/tutorials/connecting - -Step 2. Open PlatformIO in VSCode and create a new project. In the board drop down list select the "Digispark USB (Digistump)" development board. This board has an ATTiny85 mounted on it. - -Step 3. Check your PlatformIO.ini file. It should look like this: - -``` -[env:digispark-tiny] -platform = atmelavr -board = digispark-tiny -framework = arduino -``` - -Step 4. In your main.cpp file you can write a blinky (hello world) program to get started. Here is mine: - -``` -#include - -int ledPin = 1; - -void setup() { - pinMode(ledPin, OUTPUT); -} - -void loop() { - digitalWrite(ledPin, HIGH); - delay(1000); - digitalWrite(ledPin, LOW); - delay(1000); -} -``` - -Step 5. Build and compile your source code with PlatformIO. - -Step 6. *Important*. Disconnect the USB from your Digispark ATTiny85 board before uploading. - -Step 7. Begin upload with PlatformIO. - -Step 8. When prompted reconnect the USB to your Digispark ATTiny85 board. - -Step 9. The blinky program should now be running on your Digispark ATTiny85 board. - -Note that there are 2 LEDs on this development board, there is a power and a user LED. - -For low power systems this development board uses approx. 13mA current. - -In sleep mode the current can be reduced to approx. 4mA current. - -Hacking the board a bit to remove the power LED and regulator may drop this to 2mA. -https://www.youtube.com/watch?v=fOBGdSYi318 - -Still a bit high for many low power applications. - -ArduinoNano and ArduinoMini has lower current. -http://www.home-automation-community.com/arduino-low-power-how-to-run-atmega328p-for-a-year-on-coin-cell-battery/ - -ESP32 in active mode is approx 66mA current, in deep sleep mode between 0.01mA and 19mA current depending on the development board version you have. -https://www.youtube.com/watch?v=y1R2y8dCsIg - diff --git a/exercises/drivers/linux/CP210x_VCP_Linux_4.x_Release_Notes.txt b/exercises/drivers/linux/CP210x_VCP_Linux_4.x_Release_Notes.txt deleted file mode 100644 index b55285a..0000000 --- a/exercises/drivers/linux/CP210x_VCP_Linux_4.x_Release_Notes.txt +++ /dev/null @@ -1,40 +0,0 @@ -This bundle contains a modified CP210x driver for the 4.10.0 kernel (Ubuntu 17.04). - -It contains: - -- Support for the CP2102N - -NOTE: This driver is an example of how to perform GPIO operations within the CP210x driver since -the driver on kernel.org does not support GPIO at this time. This driver has only been written -and tested on the Linux 3.13.0 kernel on Ubuntu 14.04. This driver is a modified version of the -existing driver in the Linux 3.13.0 kernel, which is maintained at kernel.org. It is recommened -to use the driver there that matches your specific kernel version: - -www.kernel.org - -Build instrutions: - -Ubuntu: -1. make ( your cp210x driver ) -2. cp cp210x.ko to /lib/modules//kernel/drivers/usb/serial -3. insmod /lib/modules//kernel/drivers/usb/serial -6a. insmod /lib/modules/ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DRIVER_DESC "Silicon Labs CP210x RS232 serial adaptor driver" - -/* - * Function Prototypes - */ -static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *); -static void cp210x_close(struct usb_serial_port *); -static int cp210x_ioctl(struct tty_struct *tty, - unsigned int cmd, unsigned long arg); -static void cp210x_get_termios(struct tty_struct *, struct usb_serial_port *); -static void cp210x_get_termios_port(struct usb_serial_port *port, - unsigned int *cflagp, unsigned int *baudp); -static void cp210x_change_speed(struct tty_struct *, struct usb_serial_port *, - struct ktermios *); -static void cp210x_set_termios(struct tty_struct *, struct usb_serial_port *, - struct ktermios*); -static bool cp210x_tx_empty(struct usb_serial_port *port); -static int cp210x_tiocmget(struct tty_struct *); -static int cp210x_tiocmset(struct tty_struct *, unsigned int, unsigned int); -static int cp210x_tiocmset_port(struct usb_serial_port *port, - unsigned int, unsigned int); -static void cp210x_break_ctl(struct tty_struct *, int); -static int cp210x_port_probe(struct usb_serial_port *); -static int cp210x_port_remove(struct usb_serial_port *); -static void cp210x_dtr_rts(struct usb_serial_port *p, int on); - -static const struct usb_device_id id_table[] = { - { USB_DEVICE(0x045B, 0x0053) }, /* Renesas RX610 RX-Stick */ - { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */ - { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */ - { USB_DEVICE(0x0489, 0xE003) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */ - { USB_DEVICE(0x0745, 0x1000) }, /* CipherLab USB CCD Barcode Scanner 1000 */ - { USB_DEVICE(0x0846, 0x1100) }, /* NetGear Managed Switch M4100 series, M5300 series, M7100 series */ - { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */ - { USB_DEVICE(0x08FD, 0x000A) }, /* Digianswer A/S , ZigBee/802.15.4 MAC Device */ - { USB_DEVICE(0x0908, 0x01FF) }, /* Siemens RUGGEDCOM USB Serial Console */ - { USB_DEVICE(0x0BED, 0x1100) }, /* MEI (TM) Cashflow-SC Bill/Voucher Acceptor */ - { USB_DEVICE(0x0BED, 0x1101) }, /* MEI series 2000 Combo Acceptor */ - { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */ - { USB_DEVICE(0x0FCF, 0x1004) }, /* Dynastream ANT2USB */ - { USB_DEVICE(0x0FCF, 0x1006) }, /* Dynastream ANT development board */ - { USB_DEVICE(0x0FDE, 0xCA05) }, /* OWL Wireless Electricity Monitor CM-160 */ - { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */ - { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */ - { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */ - { USB_DEVICE(0x10C4, 0x0F91) }, /* Vstabi */ - { USB_DEVICE(0x10C4, 0x1101) }, /* Arkham Technology DS101 Bus Monitor */ - { USB_DEVICE(0x10C4, 0x1601) }, /* Arkham Technology DS101 Adapter */ - { USB_DEVICE(0x10C4, 0x800A) }, /* SPORTident BSM7-D-USB main station */ - { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */ - { USB_DEVICE(0x10C4, 0x8044) }, /* Cygnal Debug Adapter */ - { USB_DEVICE(0x10C4, 0x804E) }, /* Software Bisque Paramount ME build-in converter */ - { USB_DEVICE(0x10C4, 0x8053) }, /* Enfora EDG1228 */ - { USB_DEVICE(0x10C4, 0x8054) }, /* Enfora GSM2228 */ - { USB_DEVICE(0x10C4, 0x8066) }, /* Argussoft In-System Programmer */ - { USB_DEVICE(0x10C4, 0x806F) }, /* IMS USB to RS422 Converter Cable */ - { USB_DEVICE(0x10C4, 0x807A) }, /* Crumb128 board */ - { USB_DEVICE(0x10C4, 0x80C4) }, /* Cygnal Integrated Products, Inc., Optris infrared thermometer */ - { USB_DEVICE(0x10C4, 0x80CA) }, /* Degree Controls Inc */ - { USB_DEVICE(0x10C4, 0x80DD) }, /* Tracient RFID */ - { USB_DEVICE(0x10C4, 0x80F6) }, /* Suunto sports instrument */ - { USB_DEVICE(0x10C4, 0x8115) }, /* Arygon NFC/Mifare Reader */ - { USB_DEVICE(0x10C4, 0x813D) }, /* Burnside Telecom Deskmobile */ - { USB_DEVICE(0x10C4, 0x813F) }, /* Tams Master Easy Control */ - { USB_DEVICE(0x10C4, 0x814A) }, /* West Mountain Radio RIGblaster P&P */ - { USB_DEVICE(0x10C4, 0x814B) }, /* West Mountain Radio RIGtalk */ - { USB_DEVICE(0x2405, 0x0003) }, /* West Mountain Radio RIGblaster Advantage */ - { USB_DEVICE(0x10C4, 0x8156) }, /* B&G H3000 link cable */ - { USB_DEVICE(0x10C4, 0x815E) }, /* Helicomm IP-Link 1220-DVM */ - { USB_DEVICE(0x10C4, 0x815F) }, /* Timewave HamLinkUSB */ - { USB_DEVICE(0x10C4, 0x818B) }, /* AVIT Research USB to TTL */ - { USB_DEVICE(0x10C4, 0x819F) }, /* MJS USB Toslink Switcher */ - { USB_DEVICE(0x10C4, 0x81A6) }, /* ThinkOptics WavIt */ - { USB_DEVICE(0x10C4, 0x81A9) }, /* Multiplex RC Interface */ - { USB_DEVICE(0x10C4, 0x81AC) }, /* MSD Dash Hawk */ - { USB_DEVICE(0x10C4, 0x81AD) }, /* INSYS USB Modem */ - { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */ - { USB_DEVICE(0x10C4, 0x81D7) }, /* IAI Corp. RCB-CV-USB USB to RS485 Adaptor */ - { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */ - { USB_DEVICE(0x10C4, 0x81E7) }, /* Aerocomm Radio */ - { USB_DEVICE(0x10C4, 0x81E8) }, /* Zephyr Bioharness */ - { USB_DEVICE(0x10C4, 0x81F2) }, /* C1007 HF band RFID controller */ - { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ - { USB_DEVICE(0x10C4, 0x822B) }, /* Modem EDGE(GSM) Comander 2 */ - { USB_DEVICE(0x10C4, 0x826B) }, /* Cygnal Integrated Products, Inc., Fasttrax GPS demonstration module */ - { USB_DEVICE(0x10C4, 0x8281) }, /* Nanotec Plug & Drive */ - { USB_DEVICE(0x10C4, 0x8293) }, /* Telegesis ETRX2USB */ - { USB_DEVICE(0x10C4, 0x82F9) }, /* Procyon AVS */ - { USB_DEVICE(0x10C4, 0x8341) }, /* Siemens MC35PU GPRS Modem */ - { USB_DEVICE(0x10C4, 0x8382) }, /* Cygnal Integrated Products, Inc. */ - { USB_DEVICE(0x10C4, 0x83A8) }, /* Amber Wireless AMB2560 */ - { USB_DEVICE(0x10C4, 0x83D8) }, /* DekTec DTA Plus VHF/UHF Booster/Attenuator */ - { USB_DEVICE(0x10C4, 0x8411) }, /* Kyocera GPS Module */ - { USB_DEVICE(0x10C4, 0x8418) }, /* IRZ Automation Teleport SG-10 GSM/GPRS Modem */ - { USB_DEVICE(0x10C4, 0x846E) }, /* BEI USB Sensor Interface (VCP) */ - { USB_DEVICE(0x10C4, 0x8477) }, /* Balluff RFID */ - { USB_DEVICE(0x10C4, 0x85EA) }, /* AC-Services IBUS-IF */ - { USB_DEVICE(0x10C4, 0x85EB) }, /* AC-Services CIS-IBUS */ - { USB_DEVICE(0x10C4, 0x85F8) }, /* Virtenio Preon32 */ - { USB_DEVICE(0x10C4, 0x8664) }, /* AC-Services CAN-IF */ - { USB_DEVICE(0x10C4, 0x8665) }, /* AC-Services OBD-IF */ - { USB_DEVICE(0x10C4, 0x8856) }, /* CEL EM357 ZigBee USB Stick - LR */ - { USB_DEVICE(0x10C4, 0x8857) }, /* CEL EM357 ZigBee USB Stick */ - { USB_DEVICE(0x10C4, 0x88A4) }, /* MMB Networks ZigBee USB Device */ - { USB_DEVICE(0x10C4, 0x88A5) }, /* Planet Innovation Ingeni ZigBee USB Device */ - { USB_DEVICE(0x10C4, 0x8946) }, /* Ketra N1 Wireless Interface */ - { USB_DEVICE(0x10C4, 0x8977) }, /* CEL MeshWorks DevKit Device */ - { USB_DEVICE(0x10C4, 0x8998) }, /* KCF Technologies PRN */ - { USB_DEVICE(0x10C4, 0x8A2A) }, /* HubZ dual ZigBee and Z-Wave dongle */ - { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ - { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */ - { USB_DEVICE(0x10C4, 0xEA70) }, /* Silicon Labs factory default */ - { USB_DEVICE(0x10C4, 0xEA71) }, /* Infinity GPS-MIC-1 Radio Monophone */ - { USB_DEVICE(0x10C4, 0xF001) }, /* Elan Digital Systems USBscope50 */ - { USB_DEVICE(0x10C4, 0xF002) }, /* Elan Digital Systems USBwave12 */ - { USB_DEVICE(0x10C4, 0xF003) }, /* Elan Digital Systems USBpulse100 */ - { USB_DEVICE(0x10C4, 0xF004) }, /* Elan Digital Systems USBcount50 */ - { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */ - { USB_DEVICE(0x10CE, 0xEA6A) }, /* Silicon Labs MobiData GPRS USB Modem 100EU */ - { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */ - { USB_DEVICE(0x1555, 0x0004) }, /* Owen AC4 USB-RS485 Converter */ - { USB_DEVICE(0x166A, 0x0201) }, /* Clipsal 5500PACA C-Bus Pascal Automation Controller */ - { USB_DEVICE(0x166A, 0x0301) }, /* Clipsal 5800PC C-Bus Wireless PC Interface */ - { USB_DEVICE(0x166A, 0x0303) }, /* Clipsal 5500PCU C-Bus USB interface */ - { USB_DEVICE(0x166A, 0x0304) }, /* Clipsal 5000CT2 C-Bus Black and White Touchscreen */ - { USB_DEVICE(0x166A, 0x0305) }, /* Clipsal C-5000CT2 C-Bus Spectrum Colour Touchscreen */ - { USB_DEVICE(0x166A, 0x0401) }, /* Clipsal L51xx C-Bus Architectural Dimmer */ - { USB_DEVICE(0x166A, 0x0101) }, /* Clipsal 5560884 C-Bus Multi-room Audio Matrix Switcher */ - { USB_DEVICE(0x16C0, 0x09B0) }, /* Lunatico Seletek */ - { USB_DEVICE(0x16C0, 0x09B1) }, /* Lunatico Seletek */ - { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */ - { USB_DEVICE(0x16DC, 0x0010) }, /* W-IE-NE-R Plein & Baus GmbH PL512 Power Supply */ - { USB_DEVICE(0x16DC, 0x0011) }, /* W-IE-NE-R Plein & Baus GmbH RCM Remote Control for MARATON Power Supply */ - { USB_DEVICE(0x16DC, 0x0012) }, /* W-IE-NE-R Plein & Baus GmbH MPOD Multi Channel Power Supply */ - { USB_DEVICE(0x16DC, 0x0015) }, /* W-IE-NE-R Plein & Baus GmbH CML Control, Monitoring and Data Logger */ - { USB_DEVICE(0x17A8, 0x0001) }, /* Kamstrup Optical Eye/3-wire */ - { USB_DEVICE(0x17A8, 0x0005) }, /* Kamstrup M-Bus Master MultiPort 250D */ - { USB_DEVICE(0x17F4, 0xAAAA) }, /* Wavesense Jazz blood glucose meter */ - { USB_DEVICE(0x1843, 0x0200) }, /* Vaisala USB Instrument Cable */ - { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */ - { USB_DEVICE(0x18EF, 0xE025) }, /* ELV Marble Sound Board 1 */ - { USB_DEVICE(0x1901, 0x0190) }, /* GE B850 CP2105 Recorder interface */ - { USB_DEVICE(0x1901, 0x0193) }, /* GE B650 CP2104 PMC interface */ - { USB_DEVICE(0x1901, 0x0194) }, /* GE Healthcare Remote Alarm Box */ - { USB_DEVICE(0x19CF, 0x3000) }, /* Parrot NMEA GPS Flight Recorder */ - { USB_DEVICE(0x1ADB, 0x0001) }, /* Schweitzer Engineering C662 Cable */ - { USB_DEVICE(0x1B1C, 0x1C00) }, /* Corsair USB Dongle */ - { USB_DEVICE(0x1BA4, 0x0002) }, /* Silicon Labs 358x factory default */ - { USB_DEVICE(0x1BE3, 0x07A6) }, /* WAGO 750-923 USB Service Cable */ - { USB_DEVICE(0x1D6F, 0x0010) }, /* Seluxit ApS RF Dongle */ - { USB_DEVICE(0x1E29, 0x0102) }, /* Festo CPX-USB */ - { USB_DEVICE(0x1E29, 0x0501) }, /* Festo CMSP */ - { USB_DEVICE(0x1FB9, 0x0100) }, /* Lake Shore Model 121 Current Source */ - { USB_DEVICE(0x1FB9, 0x0200) }, /* Lake Shore Model 218A Temperature Monitor */ - { USB_DEVICE(0x1FB9, 0x0201) }, /* Lake Shore Model 219 Temperature Monitor */ - { USB_DEVICE(0x1FB9, 0x0202) }, /* Lake Shore Model 233 Temperature Transmitter */ - { USB_DEVICE(0x1FB9, 0x0203) }, /* Lake Shore Model 235 Temperature Transmitter */ - { USB_DEVICE(0x1FB9, 0x0300) }, /* Lake Shore Model 335 Temperature Controller */ - { USB_DEVICE(0x1FB9, 0x0301) }, /* Lake Shore Model 336 Temperature Controller */ - { USB_DEVICE(0x1FB9, 0x0302) }, /* Lake Shore Model 350 Temperature Controller */ - { USB_DEVICE(0x1FB9, 0x0303) }, /* Lake Shore Model 371 AC Bridge */ - { USB_DEVICE(0x1FB9, 0x0400) }, /* Lake Shore Model 411 Handheld Gaussmeter */ - { USB_DEVICE(0x1FB9, 0x0401) }, /* Lake Shore Model 425 Gaussmeter */ - { USB_DEVICE(0x1FB9, 0x0402) }, /* Lake Shore Model 455A Gaussmeter */ - { USB_DEVICE(0x1FB9, 0x0403) }, /* Lake Shore Model 475A Gaussmeter */ - { USB_DEVICE(0x1FB9, 0x0404) }, /* Lake Shore Model 465 Three Axis Gaussmeter */ - { USB_DEVICE(0x1FB9, 0x0600) }, /* Lake Shore Model 625A Superconducting MPS */ - { USB_DEVICE(0x1FB9, 0x0601) }, /* Lake Shore Model 642A Magnet Power Supply */ - { USB_DEVICE(0x1FB9, 0x0602) }, /* Lake Shore Model 648 Magnet Power Supply */ - { USB_DEVICE(0x1FB9, 0x0700) }, /* Lake Shore Model 737 VSM Controller */ - { USB_DEVICE(0x1FB9, 0x0701) }, /* Lake Shore Model 776 Hall Matrix */ - { USB_DEVICE(0x2626, 0xEA60) }, /* Aruba Networks 7xxx USB Serial Console */ - { USB_DEVICE(0x3195, 0xF190) }, /* Link Instruments MSO-19 */ - { USB_DEVICE(0x3195, 0xF280) }, /* Link Instruments MSO-28 */ - { USB_DEVICE(0x3195, 0xF281) }, /* Link Instruments MSO-28 */ - { USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */ - { } /* Terminating Entry */ -}; - -MODULE_DEVICE_TABLE(usb, id_table); - -struct cp210x_port_private { - __u8 bPartNumber; - __u8 bInterfaceNumber; - bool has_swapped_line_ctl; -}; - -static struct usb_serial_driver cp210x_device = { - .driver = { - .owner = THIS_MODULE, - .name = "cp210x", - }, - .id_table = id_table, - .num_ports = 1, - .bulk_in_size = 256, - .bulk_out_size = 256, - .open = cp210x_open, - .close = cp210x_close, - .ioctl = cp210x_ioctl, - .break_ctl = cp210x_break_ctl, - .set_termios = cp210x_set_termios, - .tx_empty = cp210x_tx_empty, - .tiocmget = cp210x_tiocmget, - .tiocmset = cp210x_tiocmset, - .port_probe = cp210x_port_probe, - .port_remove = cp210x_port_remove, - .dtr_rts = cp210x_dtr_rts -}; - -/* IOCTLs */ -#define IOCTL_GPIOGET 0x8000 -#define IOCTL_GPIOSET 0x8001 - -static struct usb_serial_driver * const serial_drivers[] = { - &cp210x_device, NULL -}; - -/* Config request types */ -#define REQTYPE_HOST_TO_INTERFACE 0x41 -#define REQTYPE_INTERFACE_TO_HOST 0xc1 -#define REQTYPE_HOST_TO_DEVICE 0x40 -#define REQTYPE_DEVICE_TO_HOST 0xc0 - -/* Config request codes */ -#define CP210X_IFC_ENABLE 0x00 -#define CP210X_SET_BAUDDIV 0x01 -#define CP210X_GET_BAUDDIV 0x02 -#define CP210X_SET_LINE_CTL 0x03 -#define CP210X_GET_LINE_CTL 0x04 -#define CP210X_SET_BREAK 0x05 -#define CP210X_IMM_CHAR 0x06 -#define CP210X_SET_MHS 0x07 -#define CP210X_GET_MDMSTS 0x08 -#define CP210X_SET_XON 0x09 -#define CP210X_SET_XOFF 0x0A -#define CP210X_SET_EVENTMASK 0x0B -#define CP210X_GET_EVENTMASK 0x0C -#define CP210X_SET_CHAR 0x0D -#define CP210X_GET_CHARS 0x0E -#define CP210X_GET_PROPS 0x0F -#define CP210X_GET_COMM_STATUS 0x10 -#define CP210X_RESET 0x11 -#define CP210X_PURGE 0x12 -#define CP210X_SET_FLOW 0x13 -#define CP210X_GET_FLOW 0x14 -#define CP210X_EMBED_EVENTS 0x15 -#define CP210X_GET_EVENTSTATE 0x16 -#define CP210X_SET_CHARS 0x19 -#define CP210X_GET_BAUDRATE 0x1D -#define CP210X_SET_BAUDRATE 0x1E -#define CP210X_VENDOR_SPECIFIC 0xFF - -/* CP210X_IFC_ENABLE */ -#define UART_ENABLE 0x0001 -#define UART_DISABLE 0x0000 - -/* CP210X_(SET|GET)_BAUDDIV */ -#define BAUD_RATE_GEN_FREQ 0x384000 - -/* CP210X_(SET|GET)_LINE_CTL */ -#define BITS_DATA_MASK 0X0f00 -#define BITS_DATA_5 0X0500 -#define BITS_DATA_6 0X0600 -#define BITS_DATA_7 0X0700 -#define BITS_DATA_8 0X0800 -#define BITS_DATA_9 0X0900 - -#define BITS_PARITY_MASK 0x00f0 -#define BITS_PARITY_NONE 0x0000 -#define BITS_PARITY_ODD 0x0010 -#define BITS_PARITY_EVEN 0x0020 -#define BITS_PARITY_MARK 0x0030 -#define BITS_PARITY_SPACE 0x0040 - -#define BITS_STOP_MASK 0x000f -#define BITS_STOP_1 0x0000 -#define BITS_STOP_1_5 0x0001 -#define BITS_STOP_2 0x0002 - -/* CP210X_SET_BREAK */ -#define BREAK_ON 0x0001 -#define BREAK_OFF 0x0000 - -/* CP210X_(SET_MHS|GET_MDMSTS) */ -#define CONTROL_DTR 0x0001 -#define CONTROL_RTS 0x0002 -#define CONTROL_CTS 0x0010 -#define CONTROL_DSR 0x0020 -#define CONTROL_RING 0x0040 -#define CONTROL_DCD 0x0080 -#define CONTROL_WRITE_DTR 0x0100 -#define CONTROL_WRITE_RTS 0x0200 - -/* CP210X_VENDOR_SPECIFIC sub-commands passed in wValue */ -#define CP210X_WRITE_LATCH 0x37E1 -#define CP210X_READ_LATCH 0x00C2 -#define CP210X_GET_PARTNUM 0x370B - -/* CP210X_GET_PARTNUM returns one of these */ -#define CP2101_PARTNUM 0x01 -#define CP2102_PARTNUM 0x02 -#define CP2103_PARTNUM 0x03 -#define CP2104_PARTNUM 0x04 -#define CP2105_PARTNUM 0x05 -#define CP2108_PARTNUM 0x08 -#define CP210x_PARTNUM_CP2102N_QFN28 0x20 -#define CP210x_PARTNUM_CP2102N_QFN24 0x21 -#define CP210x_PARTNUM_CP2102N_QFN20 0x22 - -/* CP210X_GET_COMM_STATUS returns these 0x13 bytes */ -struct cp210x_comm_status { - __le32 ulErrors; - __le32 ulHoldReasons; - __le32 ulAmountInInQueue; - __le32 ulAmountInOutQueue; - u8 bEofReceived; - u8 bWaitForImmediate; - u8 bReserved; -} __packed; - -/* - * CP210X_PURGE - 16 bits passed in wValue of USB request. - * SiLabs app note AN571 gives a strange description of the 4 bits: - * bit 0 or bit 2 clears the transmit queue and 1 or 3 receive. - * writing 1 to all, however, purges cp2108 well enough to avoid the hang. - */ -#define PURGE_ALL 0x000f - -/* CP210X_GET_FLOW/CP210X_SET_FLOW read/write these 0x10 bytes */ -struct cp210x_flow_ctl { - __le32 ulControlHandshake; - __le32 ulFlowReplace; - __le32 ulXonLimit; - __le32 ulXoffLimit; -} __packed; - -/* cp210x_flow_ctl::ulControlHandshake */ -#define CP210X_SERIAL_DTR_MASK GENMASK(1, 0) -#define CP210X_SERIAL_DTR_SHIFT(_mode) (_mode) -#define CP210X_SERIAL_CTS_HANDSHAKE BIT(3) -#define CP210X_SERIAL_DSR_HANDSHAKE BIT(4) -#define CP210X_SERIAL_DCD_HANDSHAKE BIT(5) -#define CP210X_SERIAL_DSR_SENSITIVITY BIT(6) - -/* values for cp210x_flow_ctl::ulControlHandshake::CP210X_SERIAL_DTR_MASK */ -#define CP210X_SERIAL_DTR_INACTIVE 0 -#define CP210X_SERIAL_DTR_ACTIVE 1 -#define CP210X_SERIAL_DTR_FLOW_CTL 2 - -/* cp210x_flow_ctl::ulFlowReplace */ -#define CP210X_SERIAL_AUTO_TRANSMIT BIT(0) -#define CP210X_SERIAL_AUTO_RECEIVE BIT(1) -#define CP210X_SERIAL_ERROR_CHAR BIT(2) -#define CP210X_SERIAL_NULL_STRIPPING BIT(3) -#define CP210X_SERIAL_BREAK_CHAR BIT(4) -#define CP210X_SERIAL_RTS_MASK GENMASK(7, 6) -#define CP210X_SERIAL_RTS_SHIFT(_mode) (_mode << 6) -#define CP210X_SERIAL_XOFF_CONTINUE BIT(31) - -/* values for cp210x_flow_ctl::ulFlowReplace::CP210X_SERIAL_RTS_MASK */ -#define CP210X_SERIAL_RTS_INACTIVE 0 -#define CP210X_SERIAL_RTS_ACTIVE 1 -#define CP210X_SERIAL_RTS_FLOW_CTL 2 - -/* - * Reads a variable-sized block of CP210X_ registers, identified by req. - * Returns data into buf in native USB byte order. - */ -static int cp210x_read_reg_block(struct usb_serial_port *port, u8 req, - void *buf, int bufsize) -{ - struct usb_serial *serial = port->serial; - struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); - void *dmabuf; - int result; - - dmabuf = kmalloc(bufsize, GFP_KERNEL); - if (!dmabuf) { - /* - * FIXME Some callers don't bother to check for error, - * at least give them consistent junk until they are fixed - */ - memset(buf, 0, bufsize); - return -ENOMEM; - } - - result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), - req, REQTYPE_INTERFACE_TO_HOST, 0, - port_priv->bInterfaceNumber, dmabuf, bufsize, - USB_CTRL_SET_TIMEOUT); - if (result == bufsize) { - memcpy(buf, dmabuf, bufsize); - result = 0; - } else { - dev_err(&port->dev, "failed get req 0x%x size %d status: %d\n", - req, bufsize, result); - if (result >= 0) - result = -EPROTO; - - /* - * FIXME Some callers don't bother to check for error, - * at least give them consistent junk until they are fixed - */ - memset(buf, 0, bufsize); - } - - kfree(dmabuf); - - return result; -} - -/* - * Reads any 32-bit CP210X_ register identified by req. - */ -static int cp210x_read_u32_reg(struct usb_serial_port *port, u8 req, u32 *val) -{ - __le32 le32_val; - int err; - - err = cp210x_read_reg_block(port, req, &le32_val, sizeof(le32_val)); - if (err) { - /* - * FIXME Some callers don't bother to check for error, - * at least give them consistent junk until they are fixed - */ - *val = 0; - return err; - } - - *val = le32_to_cpu(le32_val); - - return 0; -} - -/* - * Reads any 16-bit CP210X_ register identified by req. - */ -static int cp210x_read_u16_reg(struct usb_serial_port *port, u8 req, u16 *val) -{ - __le16 le16_val; - int err; - - err = cp210x_read_reg_block(port, req, &le16_val, sizeof(le16_val)); - if (err) - return err; - - *val = le16_to_cpu(le16_val); - - return 0; -} - -/* - * Reads any 8-bit CP210X_ register identified by req. - */ -static int cp210x_read_u8_reg(struct usb_serial_port *port, u8 req, u8 *val) -{ - return cp210x_read_reg_block(port, req, val, sizeof(*val)); -} - -/* - * Writes any 16-bit CP210X_ register (req) whose value is passed - * entirely in the wValue field of the USB request. - */ -static int cp210x_write_u16_reg(struct usb_serial_port *port, u8 req, u16 val) -{ - struct usb_serial *serial = port->serial; - struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); - int result; - - result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), - req, REQTYPE_HOST_TO_INTERFACE, val, - port_priv->bInterfaceNumber, NULL, 0, - USB_CTRL_SET_TIMEOUT); - if (result < 0) { - dev_err(&port->dev, "failed set request 0x%x status: %d\n", - req, result); - } - - return result; -} - -/* - * Writes a variable-sized block of CP210X_ registers, identified by req. - * Data in buf must be in native USB byte order. - */ -static int cp210x_write_reg_block(struct usb_serial_port *port, u8 req, - void *buf, int bufsize) -{ - struct usb_serial *serial = port->serial; - struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); - void *dmabuf; - int result; - - dmabuf = kmalloc(bufsize, GFP_KERNEL); - if (!dmabuf) - return -ENOMEM; - - memcpy(dmabuf, buf, bufsize); - - result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), - req, REQTYPE_HOST_TO_INTERFACE, 0, - port_priv->bInterfaceNumber, dmabuf, bufsize, - USB_CTRL_SET_TIMEOUT); - - kfree(dmabuf); - - if (result == bufsize) { - result = 0; - } else { - dev_err(&port->dev, "failed set req 0x%x size %d status: %d\n", - req, bufsize, result); - if (result >= 0) - result = -EPROTO; - } - - return result; -} - -/* - * Writes any 32-bit CP210X_ register identified by req. - */ -static int cp210x_write_u32_reg(struct usb_serial_port *port, u8 req, u32 val) -{ - __le32 le32_val; - - le32_val = cpu_to_le32(val); - - return cp210x_write_reg_block(port, req, &le32_val, sizeof(le32_val)); -} - -/* - * Detect CP2108 GET_LINE_CTL bug and activate workaround. - * Write a known good value 0x800, read it back. - * If it comes back swapped the bug is detected. - * Preserve the original register value. - */ -static int cp210x_detect_swapped_line_ctl(struct usb_serial_port *port) -{ - struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); - u16 line_ctl_save; - u16 line_ctl_test; - int err; - - err = cp210x_read_u16_reg(port, CP210X_GET_LINE_CTL, &line_ctl_save); - if (err) - return err; - - err = cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, 0x800); - if (err) - return err; - - err = cp210x_read_u16_reg(port, CP210X_GET_LINE_CTL, &line_ctl_test); - if (err) - return err; - - if (line_ctl_test == 8) { - port_priv->has_swapped_line_ctl = true; - line_ctl_save = swab16(line_ctl_save); - } - - return cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, line_ctl_save); -} - -/* - * Must always be called instead of cp210x_read_u16_reg(CP210X_GET_LINE_CTL) - * to workaround cp2108 bug and get correct value. - */ -static int cp210x_get_line_ctl(struct usb_serial_port *port, u16 *ctl) -{ - struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); - int err; - - err = cp210x_read_u16_reg(port, CP210X_GET_LINE_CTL, ctl); - if (err) - return err; - - /* Workaround swapped bytes in 16-bit value from CP210X_GET_LINE_CTL */ - if (port_priv->has_swapped_line_ctl) - *ctl = swab16(*ctl); - - return 0; -} - -/* - * cp210x_quantise_baudrate - * Quantises the baud rate as per AN205 Table 1 - */ -static unsigned int cp210x_quantise_baudrate(unsigned int baud) -{ - if (baud <= 300) - baud = 300; - else if (baud <= 600) baud = 600; - else if (baud <= 1200) baud = 1200; - else if (baud <= 1800) baud = 1800; - else if (baud <= 2400) baud = 2400; - else if (baud <= 4000) baud = 4000; - else if (baud <= 4803) baud = 4800; - else if (baud <= 7207) baud = 7200; - else if (baud <= 9612) baud = 9600; - else if (baud <= 14428) baud = 14400; - else if (baud <= 16062) baud = 16000; - else if (baud <= 19250) baud = 19200; - else if (baud <= 28912) baud = 28800; - else if (baud <= 38601) baud = 38400; - else if (baud <= 51558) baud = 51200; - else if (baud <= 56280) baud = 56000; - else if (baud <= 58053) baud = 57600; - else if (baud <= 64111) baud = 64000; - else if (baud <= 77608) baud = 76800; - else if (baud <= 117028) baud = 115200; - else if (baud <= 129347) baud = 128000; - else if (baud <= 156868) baud = 153600; - else if (baud <= 237832) baud = 230400; - else if (baud <= 254234) baud = 250000; - else if (baud <= 273066) baud = 256000; - else if (baud <= 491520) baud = 460800; - else if (baud <= 567138) baud = 500000; - else if (baud <= 670254) baud = 576000; - else if (baud < 1000000) - baud = 921600; - else if (baud > 2000000) - baud = 2000000; - return baud; -} - -static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port) -{ - int result; - - result = cp210x_write_u16_reg(port, CP210X_IFC_ENABLE, UART_ENABLE); - if (result) { - dev_err(&port->dev, "%s - Unable to enable UART\n", __func__); - return result; - } - - /* Configure the termios structure */ - cp210x_get_termios(tty, port); - - /* The baud rate must be initialised on cp2104 */ - if (tty) - cp210x_change_speed(tty, port, NULL); - - return usb_serial_generic_open(tty, port); -} - -static void cp210x_close(struct usb_serial_port *port) -{ - usb_serial_generic_close(port); - - /* Clear both queues; cp2108 needs this to avoid an occasional hang */ - cp210x_write_u16_reg(port, CP210X_PURGE, PURGE_ALL); - - cp210x_write_u16_reg(port, CP210X_IFC_ENABLE, UART_DISABLE); -} - -/* - * Reads a variable-sized vendor-specific register identified by wValue - * Returns data into buf in native USB byte order. - */ -static int cp210x_read_vs_reg_block(struct usb_serial_port *port, u8 bmRequestType, - u16 wValue, void *buf, int bufsize) -{ - struct usb_serial *serial = port->serial; - struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); - void *dmabuf; - int result; - - dmabuf = kmalloc(bufsize, GFP_KERNEL); - if (!dmabuf) - return -ENOMEM; - - result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), - CP210X_VENDOR_SPECIFIC, bmRequestType, wValue, - port_priv->bInterfaceNumber, dmabuf, bufsize, - USB_CTRL_SET_TIMEOUT); - if (result == bufsize) { - memcpy(buf, dmabuf, bufsize); - result = 0; - } else { - dev_err(&port->dev, "failed get VENDOR_SPECIFIC wValue 0x%x size %d status: %d\n", - wValue, bufsize, result); - if (result >= 0) - result = -EPROTO; - } - - kfree(dmabuf); - - return result; -} - -/* GPIO register read from single-interface CP210x */ -static int cp210x_read_device_gpio_u8(struct usb_serial_port *port, u8 *val) -{ - return cp210x_read_vs_reg_block(port, REQTYPE_DEVICE_TO_HOST, CP210X_READ_LATCH, val, 1); -} - -/* GPIO register read from CP2105 */ -static int cp210x_read_interface_gpio_u8(struct usb_serial_port *port, u8 *val) -{ - return cp210x_read_vs_reg_block(port, REQTYPE_INTERFACE_TO_HOST, CP210X_READ_LATCH, val, 1); -} - -/* GPIO register read from CP2108 */ -static int cp210x_read_device_gpio_u16(struct usb_serial_port *port, u16 *val) -{ - __le16 le16_val; - int err = cp210x_read_vs_reg_block(port, REQTYPE_DEVICE_TO_HOST, CP210X_READ_LATCH, &le16_val, 2); - if (err) - return err; - - *val = le16_to_cpu(le16_val); - return 0; -} - -/* GPIO register write to single-interface CP210x */ -static int cp210x_write_device_gpio_u16(struct usb_serial_port *port, u16 val) -{ - int result; - - result = usb_control_msg(port->serial->dev, - usb_sndctrlpipe(port->serial->dev, 0), - CP210X_VENDOR_SPECIFIC, - REQTYPE_HOST_TO_DEVICE, - CP210X_WRITE_LATCH, /* wValue */ - val, /* wIndex */ - NULL, 0, USB_CTRL_SET_TIMEOUT); - if (result != 0) { - dev_err(&port->dev, "failed set WRITE_LATCH status: %d\n", - result); - if (result >= 0) - result = -EPROTO; - } - return result; -} - -/* - * Writes a variable-sized block of CP210X_ registers, identified by req. - * Data in buf must be in native USB byte order. - */ -static int cp210x_write_gpio_reg_block(struct usb_serial_port *port, - u8 bmRequestType, void *buf, int bufsize) -{ - struct usb_serial *serial = port->serial; - struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); - void *dmabuf; - int result; - - dmabuf = kmalloc(bufsize, GFP_KERNEL); - if (!dmabuf) - return -ENOMEM; - - memcpy(dmabuf, buf, bufsize); - - result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), - CP210X_VENDOR_SPECIFIC, bmRequestType, - CP210X_WRITE_LATCH, /* wValue */ - port_priv->bInterfaceNumber, /* wIndex */ - dmabuf, bufsize, - USB_CTRL_SET_TIMEOUT); - - kfree(dmabuf); - - if (result == bufsize) { - result = 0; - } else { - dev_err(&port->dev, "failed set WRITE_LATCH size %d status: %d\n", - bufsize, result); - if (result >= 0) - result = -EPROTO; - } - - return result; -} - -/* GPIO register write to CP2105 */ -static int cp210x_write_interface_gpio_u16(struct usb_serial_port *port, u16 val) -{ - __le16 le16_val = cpu_to_le16(val); - - return cp210x_write_gpio_reg_block(port, REQTYPE_HOST_TO_INTERFACE, &le16_val, 2); -} - -/* GPIO register write to CP2108 */ -static int cp210x_write_device_gpio_u32(struct usb_serial_port *port, u32 val) -{ - __le32 le32_val = cpu_to_le32(val); - - return cp210x_write_gpio_reg_block(port, REQTYPE_HOST_TO_DEVICE, &le32_val, 4); -} - -static int cp210x_ioctl(struct tty_struct *tty, - unsigned int cmd, unsigned long arg) -{ - struct usb_serial_port *port = tty->driver_data; - struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); - - switch (cmd) { - case IOCTL_GPIOGET: - if ((port_priv->bPartNumber == CP2103_PARTNUM) || - (port_priv->bPartNumber == CP2104_PARTNUM) || - (port_priv->bPartNumber == CP210x_PARTNUM_CP2102N_QFN28) || - (port_priv->bPartNumber == CP210x_PARTNUM_CP2102N_QFN24) || - (port_priv->bPartNumber == CP210x_PARTNUM_CP2102N_QFN20)) { - u8 gpio; - int err = cp210x_read_device_gpio_u8(port, &gpio); - if (err) - return err; - if (copy_to_user((void*)arg, &gpio, sizeof(gpio))) - return -EFAULT; - return 0; - } - else if (port_priv->bPartNumber == CP2105_PARTNUM) { - u8 gpio; - int err = cp210x_read_interface_gpio_u8(port, &gpio); - if (err) - return err; - if (copy_to_user((void*)arg, &gpio, sizeof(gpio))) - return -EFAULT; - return 0; - } - else if (port_priv->bPartNumber == CP2108_PARTNUM) { - u16 gpio; - int err = cp210x_read_device_gpio_u16(port, &gpio); - if (err) - return err; - if (copy_to_user((void*)arg, &gpio, sizeof(gpio))) - return -EFAULT; - return 0; - } - else { - return -ENOTSUPP; - } - break; - case IOCTL_GPIOSET: - if ((port_priv->bPartNumber == CP2103_PARTNUM) || - (port_priv->bPartNumber == CP2104_PARTNUM) || - (port_priv->bPartNumber == CP210x_PARTNUM_CP2102N_QFN28) || - (port_priv->bPartNumber == CP210x_PARTNUM_CP2102N_QFN24) || - (port_priv->bPartNumber == CP210x_PARTNUM_CP2102N_QFN20)) { - u16 gpio; - if (copy_from_user(&gpio, (void*)arg, sizeof(gpio))) - return -EFAULT; - return cp210x_write_device_gpio_u16(port, gpio); - } - else if (port_priv->bPartNumber == CP2105_PARTNUM) { - u16 gpio; - if (copy_from_user(&gpio, (void*)arg, sizeof(gpio))) - return -EFAULT; - return cp210x_write_interface_gpio_u16(port, gpio); - } - else if (port_priv->bPartNumber == CP2108_PARTNUM) { - u32 gpio; - if (copy_from_user(&gpio, (void*)arg, sizeof(gpio))) - return -EFAULT; - return cp210x_write_device_gpio_u32(port, gpio); - } - else { - return -ENOTSUPP; - } - break; - - default: - break; - } - - return -ENOIOCTLCMD; -} - -/* - * Read how many bytes are waiting in the TX queue. - */ -static int cp210x_get_tx_queue_byte_count(struct usb_serial_port *port, - u32 *count) -{ - struct usb_serial *serial = port->serial; - struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); - struct cp210x_comm_status *sts; - int result; - - sts = kmalloc(sizeof(*sts), GFP_KERNEL); - if (!sts) - return -ENOMEM; - - result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), - CP210X_GET_COMM_STATUS, REQTYPE_INTERFACE_TO_HOST, - 0, port_priv->bInterfaceNumber, sts, sizeof(*sts), - USB_CTRL_GET_TIMEOUT); - if (result == sizeof(*sts)) { - *count = le32_to_cpu(sts->ulAmountInOutQueue); - result = 0; - } else { - dev_err(&port->dev, "failed to get comm status: %d\n", result); - if (result >= 0) - result = -EPROTO; - } - - kfree(sts); - - return result; -} - -static bool cp210x_tx_empty(struct usb_serial_port *port) -{ - int err; - u32 count; - - err = cp210x_get_tx_queue_byte_count(port, &count); - if (err) - return true; - - return !count; -} - -/* - * cp210x_get_termios - * Reads the baud rate, data bits, parity, stop bits and flow control mode - * from the device, corrects any unsupported values, and configures the - * termios structure to reflect the state of the device - */ -static void cp210x_get_termios(struct tty_struct *tty, - struct usb_serial_port *port) -{ - unsigned int baud; - - if (tty) { - cp210x_get_termios_port(tty->driver_data, - &tty->termios.c_cflag, &baud); - tty_encode_baud_rate(tty, baud, baud); - } else { - unsigned int cflag; - cflag = 0; - cp210x_get_termios_port(port, &cflag, &baud); - } -} - -/* - * cp210x_get_termios_port - * This is the heart of cp210x_get_termios which always uses a &usb_serial_port. - */ -static void cp210x_get_termios_port(struct usb_serial_port *port, - unsigned int *cflagp, unsigned int *baudp) -{ - struct device *dev = &port->dev; - unsigned int cflag; - struct cp210x_flow_ctl flow_ctl; - u32 baud; - u16 bits; - u32 ctl_hs; - - cp210x_read_u32_reg(port, CP210X_GET_BAUDRATE, &baud); - - dev_dbg(dev, "%s - baud rate = %d\n", __func__, baud); - *baudp = baud; - - cflag = *cflagp; - - cp210x_get_line_ctl(port, &bits); - cflag &= ~CSIZE; - switch (bits & BITS_DATA_MASK) { - case BITS_DATA_5: - dev_dbg(dev, "%s - data bits = 5\n", __func__); - cflag |= CS5; - break; - case BITS_DATA_6: - dev_dbg(dev, "%s - data bits = 6\n", __func__); - cflag |= CS6; - break; - case BITS_DATA_7: - dev_dbg(dev, "%s - data bits = 7\n", __func__); - cflag |= CS7; - break; - case BITS_DATA_8: - dev_dbg(dev, "%s - data bits = 8\n", __func__); - cflag |= CS8; - break; - case BITS_DATA_9: - dev_dbg(dev, "%s - data bits = 9 (not supported, using 8 data bits)\n", __func__); - cflag |= CS8; - bits &= ~BITS_DATA_MASK; - bits |= BITS_DATA_8; - cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits); - break; - default: - dev_dbg(dev, "%s - Unknown number of data bits, using 8\n", __func__); - cflag |= CS8; - bits &= ~BITS_DATA_MASK; - bits |= BITS_DATA_8; - cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits); - break; - } - - switch (bits & BITS_PARITY_MASK) { - case BITS_PARITY_NONE: - dev_dbg(dev, "%s - parity = NONE\n", __func__); - cflag &= ~PARENB; - break; - case BITS_PARITY_ODD: - dev_dbg(dev, "%s - parity = ODD\n", __func__); - cflag |= (PARENB|PARODD); - break; - case BITS_PARITY_EVEN: - dev_dbg(dev, "%s - parity = EVEN\n", __func__); - cflag &= ~PARODD; - cflag |= PARENB; - break; - case BITS_PARITY_MARK: - dev_dbg(dev, "%s - parity = MARK\n", __func__); - cflag |= (PARENB|PARODD|CMSPAR); - break; - case BITS_PARITY_SPACE: - dev_dbg(dev, "%s - parity = SPACE\n", __func__); - cflag &= ~PARODD; - cflag |= (PARENB|CMSPAR); - break; - default: - dev_dbg(dev, "%s - Unknown parity mode, disabling parity\n", __func__); - cflag &= ~PARENB; - bits &= ~BITS_PARITY_MASK; - cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits); - break; - } - - cflag &= ~CSTOPB; - switch (bits & BITS_STOP_MASK) { - case BITS_STOP_1: - dev_dbg(dev, "%s - stop bits = 1\n", __func__); - break; - case BITS_STOP_1_5: - dev_dbg(dev, "%s - stop bits = 1.5 (not supported, using 1 stop bit)\n", __func__); - bits &= ~BITS_STOP_MASK; - cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits); - break; - case BITS_STOP_2: - dev_dbg(dev, "%s - stop bits = 2\n", __func__); - cflag |= CSTOPB; - break; - default: - dev_dbg(dev, "%s - Unknown number of stop bits, using 1 stop bit\n", __func__); - bits &= ~BITS_STOP_MASK; - cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits); - break; - } - - cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl, - sizeof(flow_ctl)); - ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake); - if (ctl_hs & CP210X_SERIAL_CTS_HANDSHAKE) { - dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__); - cflag |= CRTSCTS; - } else { - dev_dbg(dev, "%s - flow control = NONE\n", __func__); - cflag &= ~CRTSCTS; - } - - *cflagp = cflag; -} - -/* - * CP2101 supports the following baud rates: - * - * 300, 600, 1200, 1800, 2400, 4800, 7200, 9600, 14400, 19200, 28800, - * 38400, 56000, 57600, 115200, 128000, 230400, 460800, 921600 - * - * CP2102 and CP2103 support the following additional rates: - * - * 4000, 16000, 51200, 64000, 76800, 153600, 250000, 256000, 500000, - * 576000 - * - * The device will map a requested rate to a supported one, but the result - * of requests for rates greater than 1053257 is undefined (see AN205). - * - * CP2104, CP2105 and CP2110 support most rates up to 2M, 921k and 1M baud, - * respectively, with an error less than 1%. The actual rates are determined - * by - * - * div = round(freq / (2 x prescale x request)) - * actual = freq / (2 x prescale x div) - * - * For CP2104 and CP2105 freq is 48Mhz and prescale is 4 for request <= 365bps - * or 1 otherwise. - * For CP2110 freq is 24Mhz and prescale is 4 for request <= 300bps or 1 - * otherwise. - */ -static void cp210x_change_speed(struct tty_struct *tty, - struct usb_serial_port *port, struct ktermios *old_termios) -{ - u32 baud; - - baud = tty->termios.c_ospeed; - - /* This maps the requested rate to a rate valid on cp2102 or cp2103, - * or to an arbitrary rate in [1M,2M]. - * - * NOTE: B0 is not implemented. - */ - baud = cp210x_quantise_baudrate(baud); - - dev_dbg(&port->dev, "%s - setting baud rate to %u\n", __func__, baud); - if (cp210x_write_u32_reg(port, CP210X_SET_BAUDRATE, baud)) { - dev_warn(&port->dev, "failed to set baud rate to %u\n", baud); - if (old_termios) - baud = old_termios->c_ospeed; - else - baud = 9600; - } - - tty_encode_baud_rate(tty, baud, baud); -} - -static void cp210x_set_termios(struct tty_struct *tty, - struct usb_serial_port *port, struct ktermios *old_termios) -{ - struct device *dev = &port->dev; - unsigned int cflag, old_cflag; - u16 bits; - - cflag = tty->termios.c_cflag; - old_cflag = old_termios->c_cflag; - - if (tty->termios.c_ospeed != old_termios->c_ospeed) - cp210x_change_speed(tty, port, old_termios); - - /* If the number of data bits is to be updated */ - if ((cflag & CSIZE) != (old_cflag & CSIZE)) { - cp210x_get_line_ctl(port, &bits); - bits &= ~BITS_DATA_MASK; - switch (cflag & CSIZE) { - case CS5: - bits |= BITS_DATA_5; - dev_dbg(dev, "%s - data bits = 5\n", __func__); - break; - case CS6: - bits |= BITS_DATA_6; - dev_dbg(dev, "%s - data bits = 6\n", __func__); - break; - case CS7: - bits |= BITS_DATA_7; - dev_dbg(dev, "%s - data bits = 7\n", __func__); - break; - case CS8: - bits |= BITS_DATA_8; - dev_dbg(dev, "%s - data bits = 8\n", __func__); - break; - /*case CS9: - bits |= BITS_DATA_9; - dev_dbg(dev, "%s - data bits = 9\n", __func__); - break;*/ - default: - dev_dbg(dev, "cp210x driver does not support the number of bits requested, using 8 bit mode\n"); - bits |= BITS_DATA_8; - break; - } - if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits)) - dev_dbg(dev, "Number of data bits requested not supported by device\n"); - } - - if ((cflag & (PARENB|PARODD|CMSPAR)) != - (old_cflag & (PARENB|PARODD|CMSPAR))) { - cp210x_get_line_ctl(port, &bits); - bits &= ~BITS_PARITY_MASK; - if (cflag & PARENB) { - if (cflag & CMSPAR) { - if (cflag & PARODD) { - bits |= BITS_PARITY_MARK; - dev_dbg(dev, "%s - parity = MARK\n", __func__); - } else { - bits |= BITS_PARITY_SPACE; - dev_dbg(dev, "%s - parity = SPACE\n", __func__); - } - } else { - if (cflag & PARODD) { - bits |= BITS_PARITY_ODD; - dev_dbg(dev, "%s - parity = ODD\n", __func__); - } else { - bits |= BITS_PARITY_EVEN; - dev_dbg(dev, "%s - parity = EVEN\n", __func__); - } - } - } - if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits)) - dev_dbg(dev, "Parity mode not supported by device\n"); - } - - if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) { - cp210x_get_line_ctl(port, &bits); - bits &= ~BITS_STOP_MASK; - if (cflag & CSTOPB) { - bits |= BITS_STOP_2; - dev_dbg(dev, "%s - stop bits = 2\n", __func__); - } else { - bits |= BITS_STOP_1; - dev_dbg(dev, "%s - stop bits = 1\n", __func__); - } - if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits)) - dev_dbg(dev, "Number of stop bits requested not supported by device\n"); - } - - if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) { - struct cp210x_flow_ctl flow_ctl; - u32 ctl_hs; - u32 flow_repl; - - cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl, - sizeof(flow_ctl)); - ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake); - flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace); - dev_dbg(dev, "%s - read ulControlHandshake=0x%08x, ulFlowReplace=0x%08x\n", - __func__, ctl_hs, flow_repl); - - ctl_hs &= ~CP210X_SERIAL_DSR_HANDSHAKE; - ctl_hs &= ~CP210X_SERIAL_DCD_HANDSHAKE; - ctl_hs &= ~CP210X_SERIAL_DSR_SENSITIVITY; - ctl_hs &= ~CP210X_SERIAL_DTR_MASK; - ctl_hs |= CP210X_SERIAL_DTR_SHIFT(CP210X_SERIAL_DTR_ACTIVE); - if (cflag & CRTSCTS) { - ctl_hs |= CP210X_SERIAL_CTS_HANDSHAKE; - - flow_repl &= ~CP210X_SERIAL_RTS_MASK; - flow_repl |= CP210X_SERIAL_RTS_SHIFT( - CP210X_SERIAL_RTS_FLOW_CTL); - dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__); - } else { - ctl_hs &= ~CP210X_SERIAL_CTS_HANDSHAKE; - - flow_repl &= ~CP210X_SERIAL_RTS_MASK; - flow_repl |= CP210X_SERIAL_RTS_SHIFT( - CP210X_SERIAL_RTS_ACTIVE); - dev_dbg(dev, "%s - flow control = NONE\n", __func__); - } - - dev_dbg(dev, "%s - write ulControlHandshake=0x%08x, ulFlowReplace=0x%08x\n", - __func__, ctl_hs, flow_repl); - flow_ctl.ulControlHandshake = cpu_to_le32(ctl_hs); - flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl); - cp210x_write_reg_block(port, CP210X_SET_FLOW, &flow_ctl, - sizeof(flow_ctl)); - } - -} - -static int cp210x_tiocmset(struct tty_struct *tty, - unsigned int set, unsigned int clear) -{ - struct usb_serial_port *port = tty->driver_data; - return cp210x_tiocmset_port(port, set, clear); -} - -static int cp210x_tiocmset_port(struct usb_serial_port *port, - unsigned int set, unsigned int clear) -{ - u16 control = 0; - - if (set & TIOCM_RTS) { - control |= CONTROL_RTS; - control |= CONTROL_WRITE_RTS; - } - if (set & TIOCM_DTR) { - control |= CONTROL_DTR; - control |= CONTROL_WRITE_DTR; - } - if (clear & TIOCM_RTS) { - control &= ~CONTROL_RTS; - control |= CONTROL_WRITE_RTS; - } - if (clear & TIOCM_DTR) { - control &= ~CONTROL_DTR; - control |= CONTROL_WRITE_DTR; - } - - dev_dbg(&port->dev, "%s - control = 0x%.4x\n", __func__, control); - - return cp210x_write_u16_reg(port, CP210X_SET_MHS, control); -} - -static void cp210x_dtr_rts(struct usb_serial_port *p, int on) -{ - if (on) - cp210x_tiocmset_port(p, TIOCM_DTR|TIOCM_RTS, 0); - else - cp210x_tiocmset_port(p, 0, TIOCM_DTR|TIOCM_RTS); -} - -static int cp210x_tiocmget(struct tty_struct *tty) -{ - struct usb_serial_port *port = tty->driver_data; - u8 control; - int result; - - cp210x_read_u8_reg(port, CP210X_GET_MDMSTS, &control); - - result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0) - |((control & CONTROL_RTS) ? TIOCM_RTS : 0) - |((control & CONTROL_CTS) ? TIOCM_CTS : 0) - |((control & CONTROL_DSR) ? TIOCM_DSR : 0) - |((control & CONTROL_RING)? TIOCM_RI : 0) - |((control & CONTROL_DCD) ? TIOCM_CD : 0); - - dev_dbg(&port->dev, "%s - control = 0x%.2x\n", __func__, control); - - return result; -} - -static void cp210x_break_ctl(struct tty_struct *tty, int break_state) -{ - struct usb_serial_port *port = tty->driver_data; - u16 state; - - if (break_state == 0) - state = BREAK_OFF; - else - state = BREAK_ON; - dev_dbg(&port->dev, "%s - turning break %s\n", __func__, - state == BREAK_OFF ? "off" : "on"); - cp210x_write_u16_reg(port, CP210X_SET_BREAK, state); -} - -static int cp210x_port_probe(struct usb_serial_port *port) -{ - struct usb_serial *serial = port->serial; - struct usb_host_interface *cur_altsetting; - struct cp210x_port_private *port_priv; - int ret; - - port_priv = kzalloc(sizeof(*port_priv), GFP_KERNEL); - if (!port_priv) - return -ENOMEM; - - cur_altsetting = serial->interface->cur_altsetting; - port_priv->bInterfaceNumber = cur_altsetting->desc.bInterfaceNumber; - - usb_set_serial_port_data(port, port_priv); - - ret = cp210x_read_vs_reg_block(port, REQTYPE_DEVICE_TO_HOST, - CP210X_GET_PARTNUM, &port_priv->bPartNumber, 1); - if (ret) { - kfree(port_priv); - return ret; - } - - ret = cp210x_detect_swapped_line_ctl(port); - if (ret) { - kfree(port_priv); - return ret; - } - - return 0; -} - -static int cp210x_port_remove(struct usb_serial_port *port) -{ - struct cp210x_port_private *port_priv; - - port_priv = usb_get_serial_port_data(port); - kfree(port_priv); - - return 0; -} - -module_usb_serial_driver(serial_drivers, id_table); - -MODULE_DESCRIPTION(DRIVER_DESC); -MODULE_LICENSE("GPL"); diff --git a/exercises/drivers/linux/cp210x.ko b/exercises/drivers/linux/cp210x.ko deleted file mode 100644 index 2c3c744..0000000 Binary files a/exercises/drivers/linux/cp210x.ko and /dev/null differ diff --git a/exercises/drivers/linux/cp210x.mod.c b/exercises/drivers/linux/cp210x.mod.c deleted file mode 100644 index 0fc937e..0000000 --- a/exercises/drivers/linux/cp210x.mod.c +++ /dev/null @@ -1,177 +0,0 @@ -#include -#include -#include - -MODULE_INFO(vermagic, VERMAGIC_STRING); -MODULE_INFO(name, KBUILD_MODNAME); - -__visible struct module __this_module -__attribute__((section(".gnu.linkonce.this_module"))) = { - .name = KBUILD_MODNAME, - .init = init_module, -#ifdef CONFIG_MODULE_UNLOAD - .exit = cleanup_module, -#endif - .arch = MODULE_ARCH_INIT, -}; - -#ifdef RETPOLINE -MODULE_INFO(retpoline, "Y"); -#endif - -static const char __module_depends[] -__used -__attribute__((section(".modinfo"))) = -"depends=usbserial"; - -MODULE_ALIAS("usb:v045Bp0053d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v0471p066Ad*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v0489pE000d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v0489pE003d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v0745p1000d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v0846p1100d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v08E6p5501d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v08FDp000Ad*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v0908p01FFd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v0BEDp1100d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v0BEDp1101d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v0FCFp1003d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v0FCFp1004d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v0FCFp1006d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v0FDEpCA05d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10A6pAA26d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10ABp10C5d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10B5pAC70d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p0F91d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p1101d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p1601d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p800Ad*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p803Bd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8044d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p804Ed*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8053d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8054d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8066d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p806Fd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p807Ad*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p80C4d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p80CAd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p80DDd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p80F6d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8115d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p813Dd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p813Fd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p814Ad*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p814Bd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v2405p0003d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8156d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p815Ed*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p815Fd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p818Bd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p819Fd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p81A6d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p81A9d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p81ACd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p81ADd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p81C8d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p81D7d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p81E2d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p81E7d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p81E8d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p81F2d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8218d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p822Bd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p826Bd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8281d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8293d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p82F9d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8341d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8382d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p83A8d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p83D8d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8411d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8418d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p846Ed*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8477d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p85EAd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p85EBd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p85F8d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8664d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8665d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8856d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8857d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p88A4d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p88A5d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8946d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8977d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8998d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4p8A2Ad*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4pEA60d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4pEA61d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4pEA70d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4pEA71d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4pF001d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4pF002d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4pF003d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C4pF004d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10C5pEA61d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v10CEpEA6Ad*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v13ADp9999d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1555p0004d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v166Ap0201d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v166Ap0301d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v166Ap0303d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v166Ap0304d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v166Ap0305d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v166Ap0401d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v166Ap0101d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v16C0p09B0d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v16C0p09B1d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v16D6p0001d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v16DCp0010d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v16DCp0011d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v16DCp0012d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v16DCp0015d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v17A8p0001d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v17A8p0005d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v17F4pAAAAd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1843p0200d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v18EFpE00Fd*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v18EFpE025d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1901p0190d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1901p0193d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1901p0194d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v19CFp3000d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1ADBp0001d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1B1Cp1C00d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1BA4p0002d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1BE3p07A6d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1D6Fp0010d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1E29p0102d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1E29p0501d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0100d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0200d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0201d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0202d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0203d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0300d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0301d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0302d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0303d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0400d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0401d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0402d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0403d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0404d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0600d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0601d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0602d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0700d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v1FB9p0701d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v2626pEA60d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v3195pF190d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v3195pF280d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v3195pF281d*dc*dsc*dp*ic*isc*ip*in*"); -MODULE_ALIAS("usb:v413Cp9500d*dc*dsc*dp*ic*isc*ip*in*"); - -MODULE_INFO(srcversion, "2D74E682A8B5BA859E4D6BC"); diff --git a/exercises/drivers/linux/cp210x.mod.o b/exercises/drivers/linux/cp210x.mod.o deleted file mode 100644 index 5452908..0000000 Binary files a/exercises/drivers/linux/cp210x.mod.o and /dev/null differ diff --git a/exercises/drivers/linux/cp210x.o b/exercises/drivers/linux/cp210x.o deleted file mode 100644 index f7115a3..0000000 Binary files a/exercises/drivers/linux/cp210x.o and /dev/null differ diff --git a/exercises/drivers/linux/cp210x_gpio_example.c b/exercises/drivers/linux/cp210x_gpio_example.c deleted file mode 100644 index b645bd5..0000000 --- a/exercises/drivers/linux/cp210x_gpio_example.c +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include -#include -#include // to get close() define - -// Make sure you have installed the SiLabs's version of cp210x.c driver -// which has these IOCTLs implemented. -#define IOCTL_GPIOGET 0x8000 -#define IOCTL_GPIOSET 0x8001 - -#define CP2108 1 - -int main() -{ - int fd; - printf( "CP210x Serial Test\n"); - fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY); - if (fd == -1) - { - printf( "Error opening port /dev/ttyUSB0\n"); - return 1; - } - // mask = 3: gpio #1 and #0; value = 2: set #1, clear #0 - // Clearing GPIO turns LED on on SiLabs blue EK boards. -#ifdef CP2108 - unsigned short gpioread = 0x3333; - unsigned long gpio = 0x00020003; -#else - unsigned char gpioread = 0x33; - unsigned short gpio = 0x0203; -#endif - ioctl(fd, IOCTL_GPIOGET, &gpioread); - printf( "gpio read = %x\n", gpioread); - - printf( "gpio to write = %x\n", gpio); - ioctl(fd, IOCTL_GPIOSET, &gpio); - - ioctl(fd, IOCTL_GPIOGET, &gpioread); - printf( "gpio read = %x\n", gpioread); - - close(fd); - return 0; -} diff --git a/exercises/drivers/linux/modules.order b/exercises/drivers/linux/modules.order deleted file mode 100644 index b73296c..0000000 --- a/exercises/drivers/linux/modules.order +++ /dev/null @@ -1 +0,0 @@ -kernel//home/mtyers/Downloads/linux/cp210x.ko diff --git a/exercises/drivers/macos/CH34x_Install_V1.4.pkg b/exercises/drivers/macos/CH34x_Install_V1.4.pkg deleted file mode 100644 index 63fdf19..0000000 Binary files a/exercises/drivers/macos/CH34x_Install_V1.4.pkg and /dev/null differ diff --git a/exercises/drivers/macos/CP2102/Driver_CP2102_OS_X_10.12-0.0.1.pkg b/exercises/drivers/macos/CP2102/Driver_CP2102_OS_X_10.12-0.0.1.pkg deleted file mode 100644 index ca77d9a..0000000 Binary files a/exercises/drivers/macos/CP2102/Driver_CP2102_OS_X_10.12-0.0.1.pkg and /dev/null differ diff --git a/exercises/drivers/macos/CP2102/Driver_CP2102_OS_X_10.13-0.0.1.pkg b/exercises/drivers/macos/CP2102/Driver_CP2102_OS_X_10.13-0.0.1.pkg deleted file mode 100644 index 94eb025..0000000 Binary files a/exercises/drivers/macos/CP2102/Driver_CP2102_OS_X_10.13-0.0.1.pkg and /dev/null differ diff --git a/exercises/drivers/macos/CP2102/Driver_CP2102_OS_X_10.14-3.2.0.pkg b/exercises/drivers/macos/CP2102/Driver_CP2102_OS_X_10.14-3.2.0.pkg deleted file mode 100644 index b4d030e..0000000 Binary files a/exercises/drivers/macos/CP2102/Driver_CP2102_OS_X_10.14-3.2.0.pkg and /dev/null differ diff --git a/exercises/drivers/macos/Driver_CH341_OS_X_10.10-2.5.1.pkg b/exercises/drivers/macos/Driver_CH341_OS_X_10.10-2.5.1.pkg deleted file mode 100644 index d13e611..0000000 Binary files a/exercises/drivers/macos/Driver_CH341_OS_X_10.10-2.5.1.pkg and /dev/null differ diff --git a/exercises/drivers/macos/Driver_CH341_OS_X_10.12-3.0.5.pkg b/exercises/drivers/macos/Driver_CH341_OS_X_10.12-3.0.5.pkg deleted file mode 100644 index fb9e584..0000000 Binary files a/exercises/drivers/macos/Driver_CH341_OS_X_10.12-3.0.5.pkg and /dev/null differ diff --git a/exercises/drivers/macos/Driver_CH341_OS_X_10.13-3.1.5.pkg b/exercises/drivers/macos/Driver_CH341_OS_X_10.13-3.1.5.pkg deleted file mode 100644 index 36a3ae6..0000000 Binary files a/exercises/drivers/macos/Driver_CH341_OS_X_10.13-3.1.5.pkg and /dev/null differ diff --git a/exercises/drivers/macos/Driver_CH341_OS_X_10.5(universal)-1.0.0.pkg b/exercises/drivers/macos/Driver_CH341_OS_X_10.5(universal)-1.0.0.pkg deleted file mode 100644 index b38910a..0000000 Binary files a/exercises/drivers/macos/Driver_CH341_OS_X_10.5(universal)-1.0.0.pkg and /dev/null differ diff --git a/exercises/drivers/macos/Driver_CH341_OS_X_10.7-2.0.0.pkg b/exercises/drivers/macos/Driver_CH341_OS_X_10.7-2.0.0.pkg deleted file mode 100644 index a4bb999..0000000 Binary files a/exercises/drivers/macos/Driver_CH341_OS_X_10.7-2.0.0.pkg and /dev/null differ diff --git a/exercises/drivers/macos/Driver_CH341_OS_X_10.9-2.5.1.pkg b/exercises/drivers/macos/Driver_CH341_OS_X_10.9-2.5.1.pkg deleted file mode 100644 index 67f76f1..0000000 Binary files a/exercises/drivers/macos/Driver_CH341_OS_X_10.9-2.5.1.pkg and /dev/null differ diff --git a/exercises/drivers/macos/HL-340/Driver_CH341_OS_X_10.12-3.0.5.pkg b/exercises/drivers/macos/HL-340/Driver_CH341_OS_X_10.12-3.0.5.pkg deleted file mode 100644 index fb9e584..0000000 Binary files a/exercises/drivers/macos/HL-340/Driver_CH341_OS_X_10.12-3.0.5.pkg and /dev/null differ diff --git a/exercises/drivers/macos/HL-340/Driver_CH341_OS_X_10.13-3.1.5.pkg b/exercises/drivers/macos/HL-340/Driver_CH341_OS_X_10.13-3.1.5.pkg deleted file mode 100644 index 36a3ae6..0000000 Binary files a/exercises/drivers/macos/HL-340/Driver_CH341_OS_X_10.13-3.1.5.pkg and /dev/null differ diff --git a/exercises/drivers/macos/HL-340/Driver_CH341_OS_X_10.14-3.2.0.pkg b/exercises/drivers/macos/HL-340/Driver_CH341_OS_X_10.14-3.2.0.pkg deleted file mode 100644 index 2cd3ca1..0000000 Binary files a/exercises/drivers/macos/HL-340/Driver_CH341_OS_X_10.14-3.2.0.pkg and /dev/null differ diff --git a/exercises/drivers/macos/Mac_OSX_VCP_Driver.zip b/exercises/drivers/macos/Mac_OSX_VCP_Driver.zip deleted file mode 100644 index 3669325..0000000 Binary files a/exercises/drivers/macos/Mac_OSX_VCP_Driver.zip and /dev/null differ diff --git a/exercises/drivers/macos/PL-2303/Driver_PL2303_OS_X_10.12-3.0.5.pkg b/exercises/drivers/macos/PL-2303/Driver_PL2303_OS_X_10.12-3.0.5.pkg deleted file mode 100644 index fcda013..0000000 Binary files a/exercises/drivers/macos/PL-2303/Driver_PL2303_OS_X_10.12-3.0.5.pkg and /dev/null differ diff --git a/exercises/drivers/macos/PL-2303/Driver_PL2303_OS_X_10.13-3.1.5.pkg b/exercises/drivers/macos/PL-2303/Driver_PL2303_OS_X_10.13-3.1.5.pkg deleted file mode 100644 index 54dc62d..0000000 Binary files a/exercises/drivers/macos/PL-2303/Driver_PL2303_OS_X_10.13-3.1.5.pkg and /dev/null differ diff --git a/exercises/drivers/macos/PL-2303/Driver_PL2303_OS_X_10.14-3.2.0.pkg b/exercises/drivers/macos/PL-2303/Driver_PL2303_OS_X_10.14-3.2.0.pkg deleted file mode 100644 index 604b247..0000000 Binary files a/exercises/drivers/macos/PL-2303/Driver_PL2303_OS_X_10.14-3.2.0.pkg and /dev/null differ diff --git a/exercises/drivers/macos/README.md b/exercises/drivers/macos/README.md deleted file mode 100644 index 159ce3d..0000000 --- a/exercises/drivers/macos/README.md +++ /dev/null @@ -1,10 +0,0 @@ - -# Custom Drivers for MacOS - -There are drivers available for MacOS to connect to devices utilising a variety of chipsets. You should be able to identify the chipset used by your device and the version of MacOS you are running. The chipsets supported by the drivers are: - -1. PL-2303 -2. CP2102 -3. HL-340/CH-340/CH-341 - -Drivers can be found in the appropriately labelled subdirectories. diff --git a/exercises/drivers/macos/ReadMe.pdf b/exercises/drivers/macos/ReadMe.pdf deleted file mode 100644 index 83ad43b..0000000 Binary files a/exercises/drivers/macos/ReadMe.pdf and /dev/null differ diff --git a/exercises/drivers/win10/CP210x_Universal_Windows_Driver.zip b/exercises/drivers/win10/CP210x_Universal_Windows_Driver.zip deleted file mode 100644 index 35c000b..0000000 Binary files a/exercises/drivers/win10/CP210x_Universal_Windows_Driver.zip and /dev/null differ diff --git a/reading/TDD.pdf b/reading/TDD.pdf deleted file mode 100644 index ac0b06c..0000000 Binary files a/reading/TDD.pdf and /dev/null differ