Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
4582dfb103 | ||
|
8e7537560d | ||
|
a094696548 | ||
|
636c5989de | ||
|
d2856529ce |
@ -234,6 +234,8 @@ ifeq ($(strip $(LEADER_ENABLE)), yes)
|
||||
OPT_DEFS += -DLEADER_ENABLE
|
||||
endif
|
||||
|
||||
include $(DRIVER_PATH)/qwiic/qwiic.mk
|
||||
|
||||
QUANTUM_SRC:= \
|
||||
$(QUANTUM_DIR)/quantum.c \
|
||||
$(QUANTUM_DIR)/keymap_common.c \
|
||||
|
@ -43,7 +43,12 @@ static const I2CConfig i2cconfig = {
|
||||
|
||||
void i2c_init(void)
|
||||
{
|
||||
palSetGroupMode(GPIOB, GPIOB_PIN6 | GPIOB_PIN7, 0, PAL_MODE_INPUT); // Try releasing special pins for a short time
|
||||
//palSetGroupMode(GPIOB, GPIOB_PIN6 | GPIOB_PIN7, 0, PAL_MODE_INPUT);
|
||||
|
||||
// Try releasing special pins for a short time
|
||||
palSetPadMode(GPIOB, 6, PAL_MODE_INPUT);
|
||||
palSetPadMode(GPIOB, 7, PAL_MODE_INPUT);
|
||||
|
||||
chThdSleepMilliseconds(10);
|
||||
|
||||
palSetPadMode(GPIOB, 6, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP);
|
||||
@ -74,6 +79,10 @@ uint8_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t ti
|
||||
return i2cMasterReceiveTimeout(&I2C_DRIVER, (i2c_address >> 1), data, length, MS2ST(timeout));
|
||||
}
|
||||
|
||||
uint8_t i2c_transmit_receive(uint8_t address, uint8_t * tx_body, uint16_t tx_length, uint8_t * rx_body, uint16_t rx_length) {
|
||||
return i2cMasterTransmitTimeout(&I2C_DRIVER, address/2, tx_body, tx_length, rx_body, rx_length, MS2ST(100));
|
||||
}
|
||||
|
||||
uint8_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout)
|
||||
{
|
||||
i2c_address = devaddr;
|
||||
|
@ -34,6 +34,7 @@ void i2c_init(void);
|
||||
uint8_t i2c_start(uint8_t address);
|
||||
uint8_t i2c_transmit(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout);
|
||||
uint8_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout);
|
||||
uint8_t i2c_transmit_receive(uint8_t address, uint8_t * tx_body, uint16_t tx_length, uint8_t * rx_body, uint16_t rx_length);
|
||||
uint8_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
|
||||
uint8_t i2c_readReg(uint8_t devaddr, uint8_t* regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
|
||||
uint8_t i2c_stop(uint16_t timeout);
|
||||
|
1141
drivers/qwiic/hud.c
Normal file
1141
drivers/qwiic/hud.c
Normal file
File diff suppressed because it is too large
Load Diff
220
drivers/qwiic/hud.h
Normal file
220
drivers/qwiic/hud.h
Normal file
@ -0,0 +1,220 @@
|
||||
/*
|
||||
This is an example of how to write a library that allows user to pass in an I2C port
|
||||
|
||||
Nathan Seidle
|
||||
SparkFun Electronics
|
||||
|
||||
License: Public domain
|
||||
*/
|
||||
|
||||
#include < Wire.h >
|
||||
|
||||
uint16_t DisplayLimit[6] = {199, 999, 999, 999, 99, 199};
|
||||
|
||||
bool begin(TwoWire & wirePort = Wire); //If user doesn't specify then Wire will be used
|
||||
|
||||
void AdjustIconLevel(uint16_t IconNo, uint16_t IconLevel);
|
||||
void D01(uint8_t Action);
|
||||
void CC1(uint8_t Action);
|
||||
void D02(uint8_t Action);
|
||||
void CC2(uint8_t Action);
|
||||
void D03(uint8_t Action);
|
||||
void CC3(uint8_t Action);
|
||||
void D04(uint8_t Action);
|
||||
void CC4(uint8_t Action);
|
||||
void D05(uint8_t Action);
|
||||
void CC5(uint8_t Action);
|
||||
void D06(uint8_t Action);
|
||||
void CC6(uint8_t Action);
|
||||
void D07(uint8_t Action);
|
||||
void CC7(uint8_t Action);
|
||||
void D08(uint8_t Action);
|
||||
void CC8(uint8_t Action);
|
||||
void D0x(uint8_t Action);
|
||||
void C01(uint8_t Action);
|
||||
void C02(uint8_t Action);
|
||||
void H01(uint8_t Action);
|
||||
void K01(uint8_t Action);
|
||||
void M01(uint8_t Action);
|
||||
void C03(uint8_t Action);
|
||||
void K02(uint8_t Action);
|
||||
void M03(uint8_t Action);
|
||||
void P01(uint8_t Action);
|
||||
void P02(uint8_t Action);
|
||||
void P03(uint8_t Action);
|
||||
void T01(uint8_t Action);
|
||||
void T02(uint8_t Action);
|
||||
|
||||
void compassCircle(uint8_t Select);
|
||||
void compassArrows(uint8_t Select);
|
||||
void radarDistanceUnits(uint8_t Action);
|
||||
void flag(uint8_t Action);
|
||||
void tirePressureAlert(uint8_t Action);
|
||||
void speedometerUnits(uint8_t Action);
|
||||
void destinationDistanceUnits(uint8_t iconUnits);
|
||||
void turnDistanceUnits(uint8_t iconUnits);
|
||||
|
||||
void leftTunnel(uint8_t Action);
|
||||
void middleTunnel(uint8_t Action);
|
||||
void rightTunnel(uint8_t Action);
|
||||
void leftRoad(uint8_t Action);
|
||||
void middleRoad(uint8_t Action);
|
||||
void rightRoad(uint8_t Action);
|
||||
|
||||
void nav_Group(uint8_t Action);
|
||||
void nav_KeepLeft(uint8_t Action);
|
||||
void nav_TurnLeft(uint8_t Action);
|
||||
void nav_TurnRight(uint8_t Action);
|
||||
void nav_HardRight(uint8_t Action);
|
||||
void nav_HardLeft(uint8_t Action);
|
||||
void nav_UTurnLeft(uint8_t Action);
|
||||
void nav_UTurnRight(uint8_t Action);
|
||||
void nav_ContinueStraight(uint8_t Action);
|
||||
void nav_KeepRight(uint8_t Action);
|
||||
|
||||
void setSegmentedDisplay(uint8_t Display, uint8_t SpeedNo, bool Mode);
|
||||
|
||||
#define setHeading(SpeedNo) setSegmentedDisplay(0, SpeedNo, false)
|
||||
#define setDestinationDistance(SpeedNo, Mode) setSegmentedDisplay(1, SpeedNo, Mode)
|
||||
#define setRadarDistance(SpeedNo, Mode) setSegmentedDisplay(2, SpeedNo, Mode)
|
||||
#define setTurnDistance(SpeedNo, Mode) setSegmentedDisplay(3, SpeedNo, Mode)
|
||||
#define setTirePressure(SpeedNo, Mode) setSegmentedDisplay(4, SpeedNo, Mode)
|
||||
#define setSpeedometer(SpeedNo) setSegmentedDisplay(5, SpeedNo, false)
|
||||
|
||||
void radarDetector(uint8_t Level);
|
||||
void setCallIcon(uint8_t iconStatus);
|
||||
|
||||
void clearAll(void);
|
||||
|
||||
void IIC_Write_Command1(uint8_t IIC_Addr, uint16_t DataLen, uint8_t * DataPtr);
|
||||
void IIC_Write_Data1(uint8_t IIC_Addr, uint16_t DataLen, uint8_t * DataPtr);
|
||||
void IIC_Write_Data2(uint8_t IIC_Addr, uint16_t DataLen,
|
||||
const uint8_t * DataPtr);
|
||||
|
||||
private:
|
||||
|
||||
uint16_t S1_2_3;
|
||||
uint16_t S4_5_6;
|
||||
uint16_t S7_8_9;
|
||||
uint16_t S10_11_12;
|
||||
uint16_t S13_14;
|
||||
uint16_t S15_16_17;
|
||||
|
||||
uint16_t ChangeRedValue(uint16_t OriginalValue, uint16_t R_Value);
|
||||
uint16_t ChangeGreenValue(uint16_t OriginalValue, uint16_t G_Value);
|
||||
uint16_t ChangeBlueValue(uint16_t OriginalValue, uint16_t B_Value);
|
||||
uint16_t ChangeRG_Value(uint16_t OriginalValue, uint16_t RG_Value);
|
||||
uint16_t ChangeGB_Value(uint16_t OriginalValue, uint16_t GB_Value);
|
||||
uint16_t SetRGB_Value(uint16_t RGB_Value);
|
||||
void NumericalTo4BCD(uint16_t S_Number, uint8_t * BCD_Ptr);
|
||||
|
||||
void DispNumber(const uint16_t * SegIconPtr, uint8_t DispNo);
|
||||
|
||||
void SoftReset(unsigned char DriverNo);
|
||||
void SetOscControl(unsigned char DriverNo, unsigned char mode);
|
||||
void SetGraphicsRAMWritingDirection(unsigned char DriverNo, unsigned char mode);
|
||||
void SetInterface(unsigned char DriverNo, unsigned char mode);
|
||||
void DisplayOnOff(unsigned char DriverNo, unsigned char Val);
|
||||
void DisplayStandbyOnOff(unsigned char DriverNo, unsigned char Val);
|
||||
void SetDisplaySize(unsigned char DriverNo, unsigned char Xstart, unsigned char Xend, unsigned char Ystart, unsigned char Yend);
|
||||
void SetDotCurrent(unsigned char DriverNo, unsigned char Rlevel, unsigned char Glevel, unsigned char Blevel);
|
||||
void SetSystemClockDivisionRatio(unsigned char DriverNo, unsigned char mode);
|
||||
void SetPreChargeWidth(unsigned char DriverNo, unsigned char Val);
|
||||
void SetPeakPulseWidth(unsigned char DriverNo, unsigned char Rlevel, unsigned char Glevel, unsigned char Blevel);
|
||||
void SetPeakPulseDelay(unsigned char DriverNo, unsigned char Val);
|
||||
void SetRowScanOperation(unsigned char DriverNo, unsigned char mode);
|
||||
void SetInternalRegulatorforRowScan(unsigned char DriverNo, unsigned char mode);
|
||||
void DumpDataToDriver(unsigned char DriverNo, unsigned int SData);
|
||||
|
||||
void initializeHUD231(void);
|
||||
|
||||
const uint8_t IIC_Addr[2] = { 0x30, 0x31 };
|
||||
|
||||
const uint8_t NumberSegTable[11] = { 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x00 };
|
||||
|
||||
// T TR BR B BL TL M
|
||||
const uint8_t SegIconTable[6][3][7] = {{{ 0, 6, 7, 0, 0, 0, 0 },
|
||||
{ 10, 16, 14, 13, 12, 11, 15 },
|
||||
{ 19, 25, 23, 22, 21, 20, 24 }
|
||||
},
|
||||
{{ 33, 39, 37, 36, 35, 34, 38 },
|
||||
{ 41, 47, 45, 44, 43, 42, 46 },
|
||||
{ 49, 55, 53, 52, 51, 50, 54 }
|
||||
},
|
||||
{{ 59, 65, 63, 62, 61, 60, 64 },
|
||||
{ 66, 72, 70, 69, 68, 67, 71 },
|
||||
{ 73, 79, 77, 76, 75, 74, 78 }
|
||||
},
|
||||
{{ 131, 137, 135, 134, 133, 132, 136 },
|
||||
{ 138, 144, 142, 141, 140, 139, 143 },
|
||||
{ 146, 152, 150, 149, 148, 147, 151 }
|
||||
},
|
||||
{{ 0, 0, 0, 0, 0, 0, 0 },
|
||||
{ 182, 188, 186, 185, 184, 183, 187 },
|
||||
{ 190, 196, 194, 193, 192, 191, 195 }
|
||||
},
|
||||
{{ 0, 214, 215, 0, 0, 0, 0 },
|
||||
{ 216, 222, 220, 219, 218, 217, 221 },
|
||||
{ 223, 229, 227, 226, 225, 224, 228 }
|
||||
}};
|
||||
|
||||
typedef struct {
|
||||
uint8_t DriverNo;
|
||||
uint16_t StartBumpLocation;
|
||||
uint8_t BumpNo;
|
||||
uint8_t Level;
|
||||
} IconStruct;
|
||||
|
||||
const IconStruct IconData[231] = {
|
||||
{0, 0, 2, 30}, {0, 2, 2, 30}, {0, 4, 2, 30}, {0, 6, 2, 30}, {0, 8, 2, 30},
|
||||
{0, 10, 2, 30}, {0, 12, 1, 30}, {0, 13, 1, 30}, {0, 14, 2, 30}, {0, 16, 2, 30},
|
||||
{0, 18, 2, 30}, {0, 20, 1, 30}, {0, 21, 1, 30}, {0, 22, 2, 30}, {0, 24, 1, 30},
|
||||
{0, 25, 1, 30}, {0, 26, 1, 30}, {0, 27, 2, 30}, {0, 29, 2, 30}, {0, 31, 2, 30},
|
||||
{0, 33, 1, 30}, {0, 34, 1, 30}, {0, 35, 2, 30}, {0, 37, 1, 30}, {0, 38, 1, 30},
|
||||
{0, 39, 1, 30}, {0, 40, 2, 30}, {0, 42, 2, 30}, {0, 44, 2, 30}, {0, 46, 2, 30},
|
||||
{0, 48, 2, 30}, {0, 50, 2, 30}, {0, 52, 16, 30}, {0, 68, 3, 30}, {0, 71, 3, 30},
|
||||
{0, 74, 3, 30}, {0, 77, 3, 30}, {0, 80, 3, 30}, {0, 83, 3, 30}, {0, 86, 3, 30},
|
||||
{0, 89, 1, 30}, {0, 90, 3, 30}, {0, 93, 3, 30}, {0, 96, 3, 30}, {0, 99, 3, 30},
|
||||
{0, 102, 3, 30}, {0, 105, 3, 30}, {0, 108, 3, 30}, {0, 111, 1, 30}, {0, 112, 3, 30},
|
||||
{0, 115, 3, 30}, {0, 118, 3, 30}, {0, 121, 3, 30}, {0, 124, 3, 30}, {0, 127, 3, 30},
|
||||
{0, 130, 3, 30}, {0, 133, 4, 30}, {0, 137, 6, 30}, {0, 143, 5, 30}, {0, 148, 2, 30},
|
||||
{0, 150, 1, 30}, {0, 151, 1, 30}, {0, 152, 2, 30}, {0, 154, 1, 30}, {0, 155, 1, 30},
|
||||
{0, 156, 1, 30}, {0, 157, 2, 30}, {0, 159, 1, 30}, {0, 160, 1, 30}, {0, 161, 2, 30},
|
||||
{0, 163, 1, 30}, {0, 164, 1, 30}, {0, 165, 1, 30}, {0, 166, 2, 30}, {0, 168, 1, 30},
|
||||
{0, 169, 1, 30}, {0, 170, 2, 30}, {0, 172, 1, 30}, {0, 173, 1, 30}, {0, 174, 1, 30},
|
||||
{0, 175, 3, 30}, {0, 178, 7, 30}, {0, 185, 1, 3}, {0, 186, 1, 3}, {0, 187, 1, 3},
|
||||
{0, 188, 1, 3}, {0, 189, 1, 3}, {0, 190, 1, 3}, {0, 191, 1, 3}, {0, 192, 1, 30},
|
||||
{0, 193, 2, 30}, {0, 195, 2, 30}, {0, 197, 1, 30}, {0, 198, 1, 30}, {0, 199, 2, 30},
|
||||
{0, 201, 1, 30}, {0, 202, 1, 30}, {0, 203, 3, 30}, {0, 206, 1, 30}, {0, 207, 1, 30},
|
||||
{0, 208, 1, 30}, {0, 209, 1, 30}, {0, 210, 3, 30}, {0, 213, 5, 30}, {0, 218, 4, 30},
|
||||
{0, 222, 1, 5}, {0, 223, 1, 12}, {0, 224, 6, 30}, {0, 230, 2, 30}, {0, 232, 5, 30},
|
||||
{0, 237, 4, 30}, {0, 241, 1, 5}, {0, 242, 1, 12}, {0, 243, 5, 30}, {0, 248, 2, 30},
|
||||
{0, 250, 5, 30}, {0, 255, 3, 30}, {0, 258, 2, 30}, {0, 260, 3, 30}, {0, 263, 1, 15},
|
||||
{0, 264, 1, 30}, {0, 265, 1, 15}, {0, 266, 1, 10}, {0, 267, 4, 30}, {0, 271, 1, 30},
|
||||
{0, 272, 2, 30}, {0, 274, 5, 30}, {0, 279, 4, 30}, {0, 283, 1, 5}, {0, 284, 7, 20},
|
||||
{0, 291, 4, 31}, {0, 295, 1, 15}, {0, 296, 1, 15}, {0, 297, 1, 15}, {0, 298, 1, 15},
|
||||
{0, 299, 1, 15}, {0, 300, 1, 15}, {0, 301, 1, 15}, {0, 302, 1, 15}, {0, 303, 1, 15},
|
||||
{0, 304, 1, 15}, {0, 305, 1, 15}, {0, 306, 1, 15}, {0, 307, 1, 15}, {0, 308, 1, 15},
|
||||
{0, 309, 1, 5}, {0, 310, 1, 15}, {0, 311, 1, 15}, {0, 312, 1, 15}, {0, 313, 1, 15},
|
||||
{0, 314, 1, 15}, {0, 315, 1, 15}, {0, 316, 1, 15}, {0, 317, 2, 15}, {0, 319, 2, 15},
|
||||
{0, 321, 7, 20}, {0, 328, 1, 5}, {0, 329, 4, 30}, {0, 333, 5, 30}, {0, 338, 2, 30},
|
||||
{0, 340, 1, 30}, {0, 341, 4, 30}, {0, 345, 1, 10}, {0, 346, 1, 12}, {0, 347, 1, 30},
|
||||
{0, 348, 1, 15}, {0, 349, 3, 30}, {0, 352, 2, 30}, {0, 354, 3, 30}, {0, 357, 5, 30},
|
||||
{0, 362, 2, 30}, {0, 364, 5, 30}, {0, 369, 1, 12}, {0, 370, 1, 5}, {0, 371, 4, 30},
|
||||
{0, 375, 5, 30}, {0, 380, 2, 30}, {1, 0, 6, 30}, {1, 6, 1, 12}, {1, 7, 4, 30},
|
||||
{1, 11, 2, 30}, {1, 13, 5, 30}, {1, 18, 1, 15}, {1, 19, 1, 15}, {1, 20, 1, 15},
|
||||
{1, 21, 1, 15}, {1, 22, 1, 15}, {1, 23, 1, 15}, {1, 24, 1, 15}, {1, 25, 2, 30},
|
||||
{1, 27, 1, 15}, {1, 28, 1, 15}, {1, 29, 1, 15}, {1, 30, 1, 15}, {1, 31, 1, 15},
|
||||
{1, 32, 1, 15}, {1, 33, 1, 15}, {1, 34, 28, 30}, {1, 62, 1, 30}, {1, 63, 1, 30},
|
||||
{1, 64, 1, 30}, {1, 65, 1, 30}, {1, 66, 3, 30}, {1, 69, 1, 30}, {1, 70, 1, 30},
|
||||
{1, 71, 2, 30}, {1, 73, 1, 30}, {1, 74, 1, 30}, {1, 75, 2, 30}, {1, 77, 2, 30},
|
||||
{1, 79, 1, 30}, {1, 80, 6, 30}, {1, 86, 5, 30}, {1, 91, 2, 30}, {1, 93, 17, 30},
|
||||
{1, 110, 16, 30}, {1, 126, 18, 30}, {1, 144, 14, 30}, {1, 158, 14, 30}, {1, 172, 17, 30},
|
||||
{1, 189, 17, 30}, {1, 206, 16, 30}, {1, 222, 16, 30}, {1, 238, 18, 30}, {1, 256, 14, 30},
|
||||
{1, 270, 14, 30}, {1, 284, 17, 30}, {1, 301, 17, 30}, {1, 318, 16, 30}, {1, 334, 16, 30},
|
||||
{1, 350, 33, 30}
|
||||
};
|
||||
|
||||
uint16_t IconRamMap[2][128];
|
||||
uint8_t SendDataBuffer[1024]; //1024
|
||||
uint8_t ReceiveData[1024]; //1024
|
125
drivers/qwiic/joystiic.c
Normal file
125
drivers/qwiic/joystiic.c
Normal file
@ -0,0 +1,125 @@
|
||||
/* Copyright 2018 Jack Humbert <jack.humb@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "joystiic.h"
|
||||
#include "print.h"
|
||||
#include "action.h"
|
||||
|
||||
#define JOYSTIIC_DEFAULT_ADDR 0x20
|
||||
#define JOYSTIIC_COMMAND_HORIZONTAL 0x00
|
||||
#define JOYSTIIC_COMMAND_VERTICAL 0x02
|
||||
#define JOYSTIIC_COMMAND_BUTTON 0x04
|
||||
|
||||
#define JOYSTIIC_CENTER 512
|
||||
#define JOYSTIIC_DEADZONE 200
|
||||
|
||||
uint16_t joystiic_horizontal;
|
||||
uint16_t joystiic_vertical;
|
||||
bool joystiic_button;
|
||||
|
||||
uint8_t joystiic_tx[1];
|
||||
uint8_t joystiic_rx_horizontal[2];
|
||||
uint8_t joystiic_rx_vertical[2];
|
||||
uint8_t joystiic_rx_button[1];
|
||||
|
||||
bool joystiic_triggered[5] = {0};
|
||||
|
||||
void joystiic_init(void) {
|
||||
i2c_init();
|
||||
i2c_start(JOYSTIIC_DEFAULT_ADDR);
|
||||
}
|
||||
|
||||
void joystiic_update(uint16_t horizontal, uint16_t vertical, bool button) {
|
||||
joystiic_update_kb(horizontal, vertical, button);
|
||||
joystiic_update_user(horizontal, vertical, button);
|
||||
}
|
||||
|
||||
__attribute__ ((weak))
|
||||
void joystiic_update_kb(uint16_t horizontal, uint16_t vertical, bool button) { }
|
||||
|
||||
__attribute__ ((weak))
|
||||
void joystiic_update_user(uint16_t horizontal, uint16_t vertical, bool button) { }
|
||||
|
||||
void joystiic_trigger(uint8_t trigger, bool active) {
|
||||
joystiic_trigger_kb(trigger, active);
|
||||
joystiic_trigger_user(trigger, active);
|
||||
}
|
||||
|
||||
__attribute__ ((weak))
|
||||
void joystiic_trigger_kb(uint8_t trigger, bool active) { }
|
||||
|
||||
__attribute__ ((weak))
|
||||
void joystiic_trigger_user(uint8_t trigger, bool active) { }
|
||||
|
||||
void joystiic_trigger_if_not(uint8_t trigger, bool active) {
|
||||
if (joystiic_triggered[trigger] != active) {
|
||||
joystiic_triggered[trigger] = active;
|
||||
joystiic_trigger(trigger, active);
|
||||
}
|
||||
}
|
||||
|
||||
void joystiic_task(void) {
|
||||
// get horizontal axis
|
||||
joystiic_tx[0] = JOYSTIIC_COMMAND_HORIZONTAL;
|
||||
|
||||
if (MSG_OK != i2c_transmit_receive(JOYSTIIC_DEFAULT_ADDR << 1,
|
||||
joystiic_tx, 1,
|
||||
joystiic_rx_horizontal, 2
|
||||
)) {
|
||||
printf("error hori\n");
|
||||
}
|
||||
|
||||
joystiic_horizontal = ((uint16_t)joystiic_rx_horizontal[0] << 8) | joystiic_rx_horizontal[1];
|
||||
|
||||
joystiic_trigger_if_not(JOYSTIIC_LEFT, joystiic_horizontal > (JOYSTIIC_CENTER + JOYSTIIC_DEADZONE));
|
||||
joystiic_trigger_if_not(JOYSTIIC_RIGHT, joystiic_horizontal < (JOYSTIIC_CENTER - JOYSTIIC_DEADZONE));
|
||||
|
||||
// get vertical axis
|
||||
joystiic_tx[0] = JOYSTIIC_COMMAND_VERTICAL;
|
||||
if (MSG_OK != i2c_transmit_receive(JOYSTIIC_DEFAULT_ADDR << 1,
|
||||
joystiic_tx, 1,
|
||||
joystiic_rx_vertical, 2
|
||||
)) {
|
||||
printf("error vert\n");
|
||||
}
|
||||
|
||||
joystiic_vertical = ((uint16_t)joystiic_rx_vertical[0] << 8) | joystiic_rx_vertical[1];
|
||||
|
||||
joystiic_trigger_if_not(JOYSTIIC_UP, joystiic_vertical > (JOYSTIIC_CENTER + JOYSTIIC_DEADZONE));
|
||||
joystiic_trigger_if_not(JOYSTIIC_DOWN, joystiic_vertical < (JOYSTIIC_CENTER - JOYSTIIC_DEADZONE));
|
||||
|
||||
// get button press
|
||||
joystiic_tx[0] = JOYSTIIC_COMMAND_BUTTON;
|
||||
if (MSG_OK != i2c_transmit_receive(JOYSTIIC_DEFAULT_ADDR << 1,
|
||||
joystiic_tx, 1,
|
||||
joystiic_rx_button, 1
|
||||
)) {
|
||||
printf("error vert\n");
|
||||
}
|
||||
|
||||
joystiic_button = !joystiic_rx_button[0];
|
||||
|
||||
joystiic_trigger_if_not(JOYSTIIC_PRESS, joystiic_button);
|
||||
|
||||
joystiic_update(joystiic_horizontal, joystiic_vertical, joystiic_button);
|
||||
|
||||
//printf("%d\n", joystiic[0]);
|
||||
|
||||
// SEND_STRING("H: ");
|
||||
// send_word(joystiic_rx_horizontal[0]);
|
||||
// tap_code(KC_SPACE);
|
||||
// send_word(joystiic_rx_horizontal[1]);
|
||||
// tap_code(KC_SPACE);
|
||||
}
|
34
drivers/qwiic/joystiic.h
Normal file
34
drivers/qwiic/joystiic.h
Normal file
@ -0,0 +1,34 @@
|
||||
/* Copyright 2018 Jack Humbert <jack.humb@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "qwiic.h"
|
||||
|
||||
enum {
|
||||
JOYSTIIC_LEFT,
|
||||
JOYSTIIC_RIGHT,
|
||||
JOYSTIIC_UP,
|
||||
JOYSTIIC_DOWN,
|
||||
JOYSTIIC_PRESS
|
||||
};
|
||||
|
||||
void joystiic_update_kb(uint16_t horizontal, uint16_t vertical, bool button);
|
||||
void joystiic_update_user(uint16_t horizontal, uint16_t vertical, bool button);
|
||||
void joystiic_trigger_kb(uint8_t trigger, bool active);
|
||||
void joystiic_trigger_user(uint8_t trigger, bool active);
|
||||
|
||||
void joystiic_init(void);
|
||||
void joystiic_task(void);
|
28
drivers/qwiic/qwiic.c
Normal file
28
drivers/qwiic/qwiic.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* Copyright 2018 Jack Humbert <jack.humb@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "qwiic.h"
|
||||
|
||||
void qwiic_init(void) {
|
||||
#ifdef QWIIC_JOYSTIIC_ENABLE
|
||||
joystiic_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
void qwiic_task(void) {
|
||||
#ifdef QWIIC_JOYSTIIC_ENABLE
|
||||
joystiic_task();
|
||||
#endif
|
||||
}
|
25
drivers/qwiic/qwiic.h
Normal file
25
drivers/qwiic/qwiic.h
Normal file
@ -0,0 +1,25 @@
|
||||
/* Copyright 2018 Jack Humbert <jack.humb@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "i2c_master.h"
|
||||
|
||||
#ifdef QWIIC_JOYSTIIC_ENABLE
|
||||
#include "joystiic.h"
|
||||
#endif
|
||||
|
||||
void qwiic_init(void);
|
||||
void qwiic_task(void);
|
13
drivers/qwiic/qwiic.mk
Normal file
13
drivers/qwiic/qwiic.mk
Normal file
@ -0,0 +1,13 @@
|
||||
ifneq ($(strip $(QWIIC_ENABLE)),)
|
||||
COMMON_VPATH += $(DRIVER_PATH)/qwiic
|
||||
OPT_DEFS += -DQWIIC_ENABLE
|
||||
SRC += qwiic.c
|
||||
ifeq ($(filter "i2c_master.c", $(SRC)),)
|
||||
SRC += i2c_master.c
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(filter JOYSTIIC, $(QWIIC_ENABLE)),)
|
||||
OPT_DEFS += -DQWIIC_JOYSTIIC_ENABLE
|
||||
SRC += joystiic.c
|
||||
endif
|
7
drivers/qwiic/readme.md
Normal file
7
drivers/qwiic/readme.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Qwiic Devices
|
||||
|
||||
[More info on Sparkfun's Qwiic Connect System](https://www.sparkfun.com/qwiic)
|
||||
|
||||
Currently supported devices:
|
||||
|
||||
* [Joystiic](https://www.sparkfun.com/products/14656)
|
@ -76,7 +76,7 @@
|
||||
* @brief Enables the I2C subsystem.
|
||||
*/
|
||||
#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_I2C FALSE
|
||||
#define HAL_USE_I2C TRUE
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -154,7 +154,7 @@
|
||||
/*
|
||||
* I2C driver system settings.
|
||||
*/
|
||||
#define STM32_I2C_USE_I2C1 FALSE
|
||||
#define STM32_I2C_USE_I2C1 TRUE
|
||||
#define STM32_I2C_USE_I2C2 FALSE
|
||||
#define STM32_I2C_BUSY_TIMEOUT 50
|
||||
#define STM32_I2C_I2C1_IRQ_PRIORITY 10
|
||||
|
@ -14,6 +14,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "rev6.h"
|
||||
#include "qwiic.h"
|
||||
|
||||
void matrix_init_kb(void) {
|
||||
matrix_init_user();
|
||||
@ -22,3 +23,13 @@ void matrix_init_kb(void) {
|
||||
void matrix_scan_kb(void) {
|
||||
matrix_scan_user();
|
||||
}
|
||||
|
||||
void joystiic_trigger_kb(uint8_t trigger, bool active) {
|
||||
switch (trigger) {
|
||||
case JOYSTIIC_LEFT: active ? register_code(KC_L) : unregister_code(KC_L); break;
|
||||
case JOYSTIIC_RIGHT: active ? register_code(KC_R) : unregister_code(KC_R); break;
|
||||
case JOYSTIIC_UP: active ? register_code(KC_U) : unregister_code(KC_U); break;
|
||||
case JOYSTIIC_DOWN: active ? register_code(KC_D) : unregister_code(KC_D); break;
|
||||
case JOYSTIIC_PRESS: active ? register_code(KC_P) : unregister_code(KC_P); break;
|
||||
}
|
||||
}
|
||||
|
@ -53,4 +53,5 @@ NKRO_ENABLE = yes # USB Nkey Rollover
|
||||
CUSTOM_MATRIX = yes # Custom matrix file
|
||||
AUDIO_ENABLE = yes
|
||||
RGBLIGHT_ENABLE = no
|
||||
QWIIC_ENABLE += JOYSTIIC
|
||||
# SERIAL_LINK_ENABLE = yes
|
||||
|
@ -72,6 +72,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#ifdef HD44780_ENABLE
|
||||
# include "hd44780.h"
|
||||
#endif
|
||||
#ifdef QWIIC_ENABLE
|
||||
# include "qwiic.h"
|
||||
#endif
|
||||
|
||||
#ifdef MATRIX_HAS_GHOST
|
||||
extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
|
||||
@ -157,6 +160,9 @@ void keyboard_init(void) {
|
||||
MCUCR |= _BV(JTD);
|
||||
#endif
|
||||
matrix_init();
|
||||
#ifdef QWIIC_ENABLE
|
||||
qwiic_init();
|
||||
#endif
|
||||
#ifdef PS2_MOUSE_ENABLE
|
||||
ps2_mouse_init();
|
||||
#endif
|
||||
@ -266,6 +272,10 @@ void keyboard_task(void)
|
||||
|
||||
MATRIX_LOOP_END:
|
||||
|
||||
#ifdef QWIIC_ENABLE
|
||||
qwiic_task();
|
||||
#endif
|
||||
|
||||
#ifdef MOUSEKEY_ENABLE
|
||||
// mousekey repeat & acceleration
|
||||
mousekey_task();
|
||||
|
Reference in New Issue
Block a user