changeset 1:f297755eda97 draft default tip

Add a license
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Fri, 01 Jun 2018 10:34:36 +0200
parents 6953c3fb919a
children
files LICENSE firmware/main.c
diffstat 2 files changed, 25 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LICENSE	Fri Jun 01 10:34:36 2018 +0200
@@ -0,0 +1,4 @@
+Copyright 2017 by Radomir Dopieralski.
+
+This work is licensed under a Creative Commons Attribution-ShareAlike 4.0
+International License (https://creativecommons.org/licenses/by-sa/4.0/).
--- a/firmware/main.c	Sat May 19 13:42:11 2018 +0200
+++ b/firmware/main.c	Fri Jun 01 10:34:36 2018 +0200
@@ -6,23 +6,38 @@
 
 #define I2C_ADDRESS 0x20
 volatile uint8_t command = 0;
-
+#define REGISTER_COUNT 6
+uint16_t registers[REGISTER_COUNT];
 
 void on_i2c_transmit() {
-    switch (command) {
-        default:
-            USI_TWI_Transmit_Byte(command);
+    if (command >= REGISTER_COUNT) {
+        command = 0;
     }
+    uint16_t value = registers[command];
+    USI_TWI_Transmit_Byte(value & 0xff);
+    USI_TWI_Transmit_Byte(value >> 8);
+    ++command;
 }
 
 void on_i2c_receive(int count) {
-    if (count) {
+    if (count--) {
         command = USI_TWI_Receive_Byte();
     }
+    if (command >= REGISTER_COUNT) {
+        command = 0;
+    }
+    if (count < 2) {
+        return;
+    }
+    uint16_t value = USI_TWI_Receive_Byte();
+    value |= USI_TWI_Receive_Byte() << 8;
+    registers[command] = value;
 }
 
-void main() {
+int main() {
     USI_TWI_Slave_Initialise(I2C_ADDRESS);
     USI_TWI_On_Slave_Transmit = on_i2c_transmit;
     USI_TWI_On_Slave_Receive = on_i2c_receive;
+    while (true) {
+    }
 }