aboutsummaryrefslogtreecommitdiffstats
path: root/keyboards/hotdox/left.c
diff options
context:
space:
mode:
authorlayne001365 <layne.guan@gmail.com>2019-03-12 03:41:16 +0800
committerDrashna Jaelre <drashna@live.com>2019-03-11 12:41:16 -0700
commit2a2f41c6de868c06c06cf437cf7c2b875b8c53a4 (patch)
treeb8f688d6af621a681bf6c262d029f63a704e86e1 /keyboards/hotdox/left.c
parentbf1e51ec22a8016aa02d84993241c6a85c562a0e (diff)
downloadfirmware-2a2f41c6de868c06c06cf437cf7c2b875b8c53a4.tar.gz
firmware-2a2f41c6de868c06c06cf437cf7c2b875b8c53a4.tar.bz2
firmware-2a2f41c6de868c06c06cf437cf7c2b875b8c53a4.zip
[Keyboard] Add HotDox keyboard (#5365)
* Add HotDox * Update keyboards/hotdox/config.h Co-Authored-By: layne001365 <layne.guan@gmail.com> * Update keyboards/hotdox/config.h Co-Authored-By: layne001365 <layne.guan@gmail.com> * Update keyboards/hotdox/config.h Co-Authored-By: layne001365 <layne.guan@gmail.com> * Update keyboards/hotdox/config.h Co-Authored-By: layne001365 <layne.guan@gmail.com> * Update keyboards/hotdox/keymaps/default/keymap.c Co-Authored-By: layne001365 <layne.guan@gmail.com> * * Update - keyboards/hotdox/config.h - keyboards/hotdox/hotdox.h - keyboards/hotdox/info.json - keyboards/hotdox/left.h - keyboards/hotdox/left.c - keyboards/hotdox/rules.mk * Replace EPRM with EPRM - keyboards/hotdox/keymaps/default/keymap.c - keyboards/hotdox/keymaps/eozaki/keymap.c - keyboards/hotdox/keymaps/kloki/keymap.c * Remove keymaps readme.md * Remove twimaster.h/ twimaster.c * * Update - remove FORCE_NKRO from keyboards/hotdox/config.h - keyboards/hotdox/hotdox.c - keyboards/hotdox/hotdox.h - keyboards/hotdox/keymaps/default/keymap.c - keyboards/hotdox/left.c - keyboards/hotdox/readme.md - keyboards/hotdox/rules.mk * Update keyboards/hotdox/keymaps/default/keymap.c Co-Authored-By: layne001365 <layne.guan@gmail.com> * Update keyboards/hotdox/keymaps/default/keymap.c Co-Authored-By: layne001365 <layne.guan@gmail.com> * Update keyboards/hotdox/rules.mk Co-Authored-By: layne001365 <layne.guan@gmail.com> * Update keyboards/hotdox/rules.mk Co-Authored-By: layne001365 <layne.guan@gmail.com> * Update keyboards/hotdox/rules.mk Co-Authored-By: layne001365 <layne.guan@gmail.com> * Update keyboards/hotdox/rules.mk Co-Authored-By: layne001365 <layne.guan@gmail.com> * Update keyboards/hotdox/rules.mk Co-Authored-By: layne001365 <layne.guan@gmail.com> * Update keyboards/hotdox/hotdox.h Co-Authored-By: layne001365 <layne.guan@gmail.com> * Update keyboards/hotdox/rules.mk Co-Authored-By: layne001365 <layne.guan@gmail.com> * Update keyboards/hotdox/rules.mk Co-Authored-By: layne001365 <layne.guan@gmail.com> * Update keyboards/hotdox/config.h Co-Authored-By: layne001365 <layne.guan@gmail.com> * Update keyboards/hotdox/config.h Co-Authored-By: layne001365 <layne.guan@gmail.com>
Diffstat (limited to 'keyboards/hotdox/left.c')
-rw-r--r--keyboards/hotdox/left.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/keyboards/hotdox/left.c b/keyboards/hotdox/left.c
new file mode 100644
index 000000000..ae56b1816
--- /dev/null
+++ b/keyboards/hotdox/left.c
@@ -0,0 +1,130 @@
+#include "action.h"
+#include "left.h"
+#include "wait.h"
+
+bool i2c_initialized = false;
+
+void left_config(void);
+uint8_t left_write(uint8_t reg, uint8_t data);
+uint8_t left_read(uint8_t reg, uint8_t *data);
+
+uint8_t init_mcp23017(void)
+{
+ i2c_initialized = false;
+
+ if (i2c_initialized == 0)
+ {
+ i2c_init(); // on pins D(1,0)
+ _delay_ms(1000);
+ }
+
+ return 0;
+}
+void left_init(void)
+{
+ init_mcp23017();
+ left_scan();
+#if 0
+ while (1)
+ {
+ print("wait\n");
+ wait_us(1000000);
+ }
+#endif
+}
+
+void left_scan(void)
+{
+ uint8_t ret = i2c_start(I2C_ADDR_WRITE, HOTDOX_I2C_TIMEOUT);
+
+ if (ret == 0)
+ {
+ i2c_stop(HOTDOX_I2C_TIMEOUT);
+
+ if (!i2c_initialized)
+ {
+ i2c_initialized = true;
+ left_config();
+ clear_keyboard();
+ print("mcp23017 attached!!!\n");
+ }
+ }
+ else
+ {
+ if (i2c_initialized)
+ {
+ i2c_initialized = false;
+ clear_keyboard();
+ print("mcp23017 deattached!!!\n");
+ }
+ }
+
+ return;
+}
+
+uint8_t left_read_cols(void)
+{
+ uint8_t data = 0;
+
+ left_read(MCP23017_B0_GPIOA, &data);
+
+ return data;
+}
+
+void left_unselect_rows(void)
+{
+ left_write(MCP23017_B0_IODIRB, 0x3F);
+}
+
+void left_select_row(uint8_t row)
+{
+ left_write(MCP23017_B0_IODIRB, ~(1 << row));
+}
+
+void left_config(void)
+{
+ left_write(MCP23017_B0_IODIRA, 0x7F);
+ left_write(MCP23017_B0_IPOLA, 0x7F);
+ left_write(MCP23017_B0_GPPUA, 0x7F);
+
+ left_write(MCP23017_B0_IODIRB, 0xFF);
+ left_write(MCP23017_B0_GPIOB, 0xC0);
+}
+
+uint8_t left_write(uint8_t reg, uint8_t data)
+{
+ if (!i2c_initialized)
+ {
+ return 0;
+ }
+
+ uint8_t ret;
+
+ ret = i2c_start(I2C_ADDR_WRITE, HOTDOX_I2C_TIMEOUT); if (ret) goto out;
+ ret = i2c_write(reg, HOTDOX_I2C_TIMEOUT); if (ret) goto out;
+ ret = i2c_write(data, HOTDOX_I2C_TIMEOUT);
+
+out:
+ i2c_stop(HOTDOX_I2C_TIMEOUT);
+ return ret;
+}
+
+uint8_t left_read(uint8_t reg, uint8_t *data)
+{
+ if (!i2c_initialized)
+ {
+ return 0;
+ }
+
+ uint8_t ret = 0;
+
+ ret = i2c_start(I2C_ADDR_WRITE, HOTDOX_I2C_TIMEOUT); if (ret) goto out;
+ ret = i2c_write(reg, HOTDOX_I2C_TIMEOUT); if (ret) goto out;
+ ret = i2c_start(I2C_ADDR_READ, HOTDOX_I2C_TIMEOUT); if (ret) goto out;
+
+ *data = i2c_read_nack(HOTDOX_I2C_TIMEOUT);
+
+out:
+ i2c_stop(HOTDOX_I2C_TIMEOUT);
+ return ret;
+}