Merge upstream QMK Firmware at '0.12.52~1'
This commit is contained in:
151
drivers/apa102/apa102.c
Normal file
151
drivers/apa102/apa102.c
Normal file
@@ -0,0 +1,151 @@
|
||||
/* Copyright 2020 Aldehir Rojas
|
||||
* Copyright 2017 Mikkel (Duckle29)
|
||||
*
|
||||
* 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 "apa102.h"
|
||||
#include "quantum.h"
|
||||
|
||||
#ifndef APA102_NOPS
|
||||
# if defined(__AVR__)
|
||||
# define APA102_NOPS 0 // AVR at 16 MHz already spends 62.5 ns per clock, so no extra delay is needed
|
||||
# elif defined(PROTOCOL_CHIBIOS)
|
||||
|
||||
# include "hal.h"
|
||||
# if defined(STM32F0XX) || defined(STM32F1XX) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32L0XX)
|
||||
# define APA102_NOPS (100 / (1000000000L / (STM32_SYSCLK / 4))) // This calculates how many loops of 4 nops to run to delay 100 ns
|
||||
# else
|
||||
# error("APA102_NOPS configuration required")
|
||||
# define APA102_NOPS 0 // this just pleases the compile so the above error is easier to spot
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define io_wait \
|
||||
do { \
|
||||
for (int i = 0; i < APA102_NOPS; i++) { \
|
||||
__asm__ volatile("nop\n\t" \
|
||||
"nop\n\t" \
|
||||
"nop\n\t" \
|
||||
"nop\n\t"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define APA102_SEND_BIT(byte, bit) \
|
||||
do { \
|
||||
writePin(RGB_DI_PIN, (byte >> bit) & 1); \
|
||||
io_wait; \
|
||||
writePinHigh(RGB_CI_PIN); \
|
||||
io_wait; \
|
||||
writePinLow(RGB_CI_PIN); \
|
||||
io_wait; \
|
||||
} while (0)
|
||||
|
||||
uint8_t apa102_led_brightness = APA102_DEFAULT_BRIGHTNESS;
|
||||
|
||||
void static apa102_start_frame(void);
|
||||
void static apa102_end_frame(uint16_t num_leds);
|
||||
|
||||
void static apa102_send_frame(uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness);
|
||||
void static apa102_send_byte(uint8_t byte);
|
||||
|
||||
void apa102_setleds(LED_TYPE *start_led, uint16_t num_leds) {
|
||||
LED_TYPE *end = start_led + num_leds;
|
||||
|
||||
apa102_start_frame();
|
||||
for (LED_TYPE *led = start_led; led < end; led++) {
|
||||
apa102_send_frame(led->r, led->g, led->b, apa102_led_brightness);
|
||||
}
|
||||
apa102_end_frame(num_leds);
|
||||
}
|
||||
|
||||
// Overwrite the default rgblight_call_driver to use apa102 driver
|
||||
void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { apa102_setleds(start_led, num_leds); }
|
||||
|
||||
void static apa102_init(void) {
|
||||
setPinOutput(RGB_DI_PIN);
|
||||
setPinOutput(RGB_CI_PIN);
|
||||
|
||||
writePinLow(RGB_DI_PIN);
|
||||
writePinLow(RGB_CI_PIN);
|
||||
}
|
||||
|
||||
void apa102_set_brightness(uint8_t brightness) {
|
||||
if (brightness > APA102_MAX_BRIGHTNESS) {
|
||||
apa102_led_brightness = APA102_MAX_BRIGHTNESS;
|
||||
} else if (brightness < 0) {
|
||||
apa102_led_brightness = 0;
|
||||
} else {
|
||||
apa102_led_brightness = brightness;
|
||||
}
|
||||
}
|
||||
|
||||
void static apa102_send_frame(uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness) {
|
||||
apa102_send_byte(0b11100000 | brightness);
|
||||
apa102_send_byte(blue);
|
||||
apa102_send_byte(green);
|
||||
apa102_send_byte(red);
|
||||
}
|
||||
|
||||
void static apa102_start_frame(void) {
|
||||
apa102_init();
|
||||
for (uint16_t i = 0; i < 4; i++) {
|
||||
apa102_send_byte(0);
|
||||
}
|
||||
}
|
||||
|
||||
void static apa102_end_frame(uint16_t num_leds) {
|
||||
// This function has been taken from: https://github.com/pololu/apa102-arduino/blob/master/APA102.h
|
||||
// and adapted. The code is MIT licensed. I think thats compatible?
|
||||
//
|
||||
// The data stream seen by the last LED in the chain will be delayed by
|
||||
// (count - 1) clock edges, because each LED before it inverts the clock
|
||||
// line and delays the data by one clock edge. Therefore, to make sure
|
||||
// the last LED actually receives the data we wrote, the number of extra
|
||||
// edges we send at the end of the frame must be at least (count - 1).
|
||||
//
|
||||
// Assuming we only want to send these edges in groups of size K, the
|
||||
// C/C++ expression for the minimum number of groups to send is:
|
||||
//
|
||||
// ((count - 1) + (K - 1)) / K
|
||||
//
|
||||
// The C/C++ expression above is just (count - 1) divided by K,
|
||||
// rounded up to the nearest whole number if there is a remainder.
|
||||
//
|
||||
// We set K to 16 and use the formula above as the number of frame-end
|
||||
// bytes to transfer. Each byte has 16 clock edges.
|
||||
//
|
||||
// We are ignoring the specification for the end frame in the APA102
|
||||
// datasheet, which says to send 0xFF four times, because it does not work
|
||||
// when you have 66 LEDs or more, and also it results in unwanted white
|
||||
// pixels if you try to update fewer LEDs than are on your LED strip.
|
||||
uint16_t iterations = (num_leds + 14) / 16;
|
||||
for (uint16_t i = 0; i < iterations; i++) {
|
||||
apa102_send_byte(0);
|
||||
}
|
||||
|
||||
apa102_init();
|
||||
}
|
||||
|
||||
void static apa102_send_byte(uint8_t byte) {
|
||||
APA102_SEND_BIT(byte, 7);
|
||||
APA102_SEND_BIT(byte, 6);
|
||||
APA102_SEND_BIT(byte, 5);
|
||||
APA102_SEND_BIT(byte, 4);
|
||||
APA102_SEND_BIT(byte, 3);
|
||||
APA102_SEND_BIT(byte, 2);
|
||||
APA102_SEND_BIT(byte, 1);
|
||||
APA102_SEND_BIT(byte, 0);
|
||||
}
|
||||
@@ -1,10 +1,5 @@
|
||||
/*
|
||||
* light weight WS2812 lib include
|
||||
*
|
||||
* Version 2.3 - Nev 29th 2015
|
||||
* Author: Tim (cpldcpu@gmail.com)
|
||||
*
|
||||
* Please do not change this file! All configuration is handled in "ws2812_config.h"
|
||||
/* Copyright 2020 Aldehir Rojas
|
||||
* Copyright 2017 Mikkel (Duckle29)
|
||||
*
|
||||
* 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
|
||||
@@ -22,24 +17,25 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#include "color.h"
|
||||
|
||||
#ifndef APA102_DEFAULT_BRIGHTNESS
|
||||
# define APA102_DEFAULT_BRIGHTNESS 31
|
||||
#endif
|
||||
|
||||
#define APA102_MAX_BRIGHTNESS 31
|
||||
|
||||
extern uint8_t apa102_led_brightness;
|
||||
|
||||
/* User Interface
|
||||
*
|
||||
* Input:
|
||||
* ledarray: An array of GRB data describing the LED colors
|
||||
* number_of_leds: The number of LEDs to write
|
||||
* pinmask (optional): Bitmask describing the output bin. e.g. _BV(PB0)
|
||||
* start_led: An array of GRB data describing the LED colors
|
||||
* num_leds: The number of LEDs to write
|
||||
*
|
||||
* The functions will perform the following actions:
|
||||
* - Set the data-out pin as output
|
||||
* - Send out the LED data
|
||||
* - Wait 50<EFBFBD>s to reset the LEDs
|
||||
*/
|
||||
|
||||
void apa102_setleds(LED_TYPE *ledarray, uint16_t number_of_leds);
|
||||
void apa102_setleds_pin(LED_TYPE *ledarray, uint16_t number_of_leds, uint8_t pinmask);
|
||||
void apa102_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds);
|
||||
void apa102_setleds(LED_TYPE *start_led, uint16_t num_leds);
|
||||
void apa102_set_brightness(uint8_t brightness);
|
||||
@@ -17,11 +17,10 @@
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include "serial.h"
|
||||
//#include <pro_micro.h>
|
||||
|
||||
#ifdef SOFT_SERIAL_PIN
|
||||
|
||||
# if !(defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
|
||||
# if !(defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB162__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
|
||||
# error serial.c is not supported for the currently selected MCU
|
||||
# endif
|
||||
// if using ATmega32U4/2, AT90USBxxx I2C, can not use PD0 and PD1 in soft serial.
|
||||
@@ -53,8 +52,13 @@
|
||||
# define EICRx EICRA
|
||||
# endif
|
||||
|
||||
<<<<<<< HEAD
|
||||
// ATmegaxxU2 specific config
|
||||
# if defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__)
|
||||
=======
|
||||
// ATmegaxxU2/AT90USB162 specific config
|
||||
# if defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_AT90USB162__)
|
||||
>>>>>>> 0.12.52~1
|
||||
// PD4(INT5), PD6(INT6), PD7(INT7), PC7(INT4)
|
||||
# if SOFT_SERIAL_PIN == D4
|
||||
# define EIMSK_BIT _BV(INT5)
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "quantum.h"
|
||||
#include "timer.h"
|
||||
|
||||
#if defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
|
||||
#if defined(__AVR_AT90USB162__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
|
||||
# define SPI_SCK_PIN B1
|
||||
# define SPI_MOSI_PIN B2
|
||||
# define SPI_MISO_PIN B3
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
typedef int16_t spi_status_t;
|
||||
|
||||
// Hardware SS pin is defined in the header so that user code can refer to it
|
||||
#if defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
|
||||
#if defined(__AVR_AT90USB162__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
|
||||
# define SPI_SS_PIN B0
|
||||
#elif defined(__AVR_ATmega32A__)
|
||||
# define SPI_SS_PIN B4
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
# include "sendchar.h"
|
||||
# include "timer.h"
|
||||
|
||||
struct CharacterMatrix display;
|
||||
|
||||
// Set this to 1 to help diagnose early startup problems
|
||||
// when testing power-on with ble. Turn it off otherwise,
|
||||
// as the latency of printing most of the debug info messes
|
||||
|
||||
@@ -65,7 +65,7 @@ struct CharacterMatrix {
|
||||
bool dirty;
|
||||
};
|
||||
|
||||
struct CharacterMatrix display;
|
||||
extern struct CharacterMatrix display;
|
||||
|
||||
bool iota_gfx_init(void);
|
||||
void iota_gfx_task(void);
|
||||
|
||||
170
drivers/avr/uart.c
Normal file
170
drivers/avr/uart.c
Normal file
@@ -0,0 +1,170 @@
|
||||
/* UART Example for Teensy USB Development Board
|
||||
* http://www.pjrc.com/teensy/
|
||||
* Copyright (c) 2009 PJRC.COM, LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Version 1.0: Initial Release
|
||||
// Version 1.1: Add support for Teensy 2.0, minor optimizations
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#include "uart.h"
|
||||
|
||||
#if defined(__AVR_AT90USB162__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
|
||||
# define UDRn UDR1
|
||||
# define UBRRnL UBRR1L
|
||||
# define UCSRnA UCSR1A
|
||||
# define UCSRnB UCSR1B
|
||||
# define UCSRnC UCSR1C
|
||||
# define U2Xn U2X1
|
||||
# define RXENn RXEN1
|
||||
# define TXENn TXEN1
|
||||
# define RXCIEn RXCIE1
|
||||
# define UCSZn1 UCSZ11
|
||||
# define UCSZn0 UCSZ10
|
||||
# define UDRIEn UDRIE1
|
||||
# define USARTn_UDRE_vect USART1_UDRE_vect
|
||||
# define USARTn_RX_vect USART1_RX_vect
|
||||
#elif defined(__AVR_ATmega32A__)
|
||||
# define UDRn UDR
|
||||
# define UBRRnL UBRRL
|
||||
# define UCSRnA UCSRA
|
||||
# define UCSRnB UCSRB
|
||||
# define UCSRnC UCSRC
|
||||
# define U2Xn U2X
|
||||
# define RXENn RXEN
|
||||
# define TXENn TXEN
|
||||
# define RXCIEn RXCIE
|
||||
# define UCSZn1 UCSZ1
|
||||
# define UCSZn0 UCSZ0
|
||||
# define UDRIEn UDRIE
|
||||
# define USARTn_UDRE_vect USART_UDRE_vect
|
||||
# define USARTn_RX_vect USART_RX_vect
|
||||
#elif defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
|
||||
# define UDRn UDR0
|
||||
# define UBRRnL UBRR0L
|
||||
# define UCSRnA UCSR0A
|
||||
# define UCSRnB UCSR0B
|
||||
# define UCSRnC UCSR0C
|
||||
# define U2Xn U2X0
|
||||
# define RXENn RXEN0
|
||||
# define TXENn TXEN0
|
||||
# define RXCIEn RXCIE0
|
||||
# define UCSZn1 UCSZ01
|
||||
# define UCSZn0 UCSZ00
|
||||
# define UDRIEn UDRIE0
|
||||
# define USARTn_UDRE_vect USART_UDRE_vect
|
||||
# define USARTn_RX_vect USART_RX_vect
|
||||
#endif
|
||||
|
||||
// These buffers may be any size from 2 to 256 bytes.
|
||||
#define RX_BUFFER_SIZE 64
|
||||
#define TX_BUFFER_SIZE 256
|
||||
|
||||
static volatile uint8_t tx_buffer[TX_BUFFER_SIZE];
|
||||
static volatile uint8_t tx_buffer_head;
|
||||
static volatile uint8_t tx_buffer_tail;
|
||||
static volatile uint8_t rx_buffer[RX_BUFFER_SIZE];
|
||||
static volatile uint8_t rx_buffer_head;
|
||||
static volatile uint8_t rx_buffer_tail;
|
||||
|
||||
// Initialize the UART
|
||||
void uart_init(uint32_t baud) {
|
||||
cli();
|
||||
UBRRnL = (F_CPU / 4 / baud - 1) / 2;
|
||||
UCSRnA = (1 << U2Xn);
|
||||
UCSRnB = (1 << RXENn) | (1 << TXENn) | (1 << RXCIEn);
|
||||
UCSRnC = (1 << UCSZn1) | (1 << UCSZn0);
|
||||
tx_buffer_head = tx_buffer_tail = 0;
|
||||
rx_buffer_head = rx_buffer_tail = 0;
|
||||
sei();
|
||||
}
|
||||
|
||||
// Transmit a byte
|
||||
void uart_putchar(uint8_t c) {
|
||||
uint8_t i;
|
||||
|
||||
i = tx_buffer_head + 1;
|
||||
if (i >= TX_BUFFER_SIZE) i = 0;
|
||||
// return immediately to avoid deadlock when interrupt is disabled(called from ISR)
|
||||
if (tx_buffer_tail == i && (SREG & (1 << SREG_I)) == 0) return;
|
||||
while (tx_buffer_tail == i)
|
||||
; // wait until space in buffer
|
||||
// cli();
|
||||
tx_buffer[i] = c;
|
||||
tx_buffer_head = i;
|
||||
UCSRnB = (1 << RXENn) | (1 << TXENn) | (1 << RXCIEn) | (1 << UDRIEn);
|
||||
// sei();
|
||||
}
|
||||
|
||||
// Receive a byte
|
||||
uint8_t uart_getchar(void) {
|
||||
uint8_t c, i;
|
||||
|
||||
while (rx_buffer_head == rx_buffer_tail)
|
||||
; // wait for character
|
||||
i = rx_buffer_tail + 1;
|
||||
if (i >= RX_BUFFER_SIZE) i = 0;
|
||||
c = rx_buffer[i];
|
||||
rx_buffer_tail = i;
|
||||
return c;
|
||||
}
|
||||
|
||||
// Return whether the number of bytes waiting in the receive buffer is nonzero.
|
||||
// Call this before uart_getchar() to check if it will need
|
||||
// to wait for a byte to arrive.
|
||||
bool uart_available(void) {
|
||||
uint8_t head, tail;
|
||||
|
||||
head = rx_buffer_head;
|
||||
tail = rx_buffer_tail;
|
||||
if (head >= tail) return (head - tail) > 0;
|
||||
return (RX_BUFFER_SIZE + head - tail) > 0;
|
||||
}
|
||||
|
||||
// Transmit Interrupt
|
||||
ISR(USARTn_UDRE_vect) {
|
||||
uint8_t i;
|
||||
|
||||
if (tx_buffer_head == tx_buffer_tail) {
|
||||
// buffer is empty, disable transmit interrupt
|
||||
UCSRnB = (1 << RXENn) | (1 << TXENn) | (1 << RXCIEn);
|
||||
} else {
|
||||
i = tx_buffer_tail + 1;
|
||||
if (i >= TX_BUFFER_SIZE) i = 0;
|
||||
UDRn = tx_buffer[i];
|
||||
tx_buffer_tail = i;
|
||||
}
|
||||
}
|
||||
|
||||
// Receive Interrupt
|
||||
ISR(USARTn_RX_vect) {
|
||||
uint8_t c, i;
|
||||
|
||||
c = UDRn;
|
||||
i = rx_buffer_head + 1;
|
||||
if (i >= RX_BUFFER_SIZE) i = 0;
|
||||
if (i != rx_buffer_tail) {
|
||||
rx_buffer[i] = c;
|
||||
rx_buffer_head = i;
|
||||
}
|
||||
}
|
||||
35
drivers/avr/uart.h
Normal file
35
drivers/avr/uart.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/* UART Example for Teensy USB Development Board
|
||||
* http://www.pjrc.com/teensy/
|
||||
* Copyright (c) 2009 PJRC.COM, LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void uart_init(uint32_t baud);
|
||||
|
||||
void uart_putchar(uint8_t c);
|
||||
|
||||
uint8_t uart_getchar(void);
|
||||
|
||||
bool uart_available(void);
|
||||
@@ -67,19 +67,27 @@ void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds) {
|
||||
#define w_onecycles (((F_CPU / 1000) * w_onepulse + 500000) / 1000000)
|
||||
#define w_totalcycles (((F_CPU / 1000) * w_totalperiod + 500000) / 1000000)
|
||||
|
||||
// w1 - nops between rising edge and falling edge - low
|
||||
#define w1 (w_zerocycles - w_fixedlow)
|
||||
// w2 nops between fe low and fe high
|
||||
#define w2 (w_onecycles - w_fixedhigh - w1)
|
||||
// w3 nops to complete loop
|
||||
#define w3 (w_totalcycles - w_fixedtotal - w1 - w2)
|
||||
|
||||
#if w1 > 0
|
||||
# define w1_nops w1
|
||||
// w1_nops - nops between rising edge and falling edge - low
|
||||
#if w_zerocycles >= w_fixedlow
|
||||
# define w1_nops (w_zerocycles - w_fixedlow)
|
||||
#else
|
||||
# define w1_nops 0
|
||||
#endif
|
||||
|
||||
// w2_nops - nops between fe low and fe high
|
||||
#if w_onecycles >= (w_fixedhigh + w1_nops)
|
||||
# define w2_nops (w_onecycles - w_fixedhigh - w1_nops)
|
||||
#else
|
||||
# define w2_nops 0
|
||||
#endif
|
||||
|
||||
// w3_nops - nops to complete loop
|
||||
#if w_totalcycles >= (w_fixedtotal + w1_nops + w2_nops)
|
||||
# define w3_nops (w_totalcycles - w_fixedtotal - w1_nops - w2_nops)
|
||||
#else
|
||||
# define w3_nops 0
|
||||
#endif
|
||||
|
||||
// The only critical timing parameter is the minimum pulse length of the "0"
|
||||
// Warn or throw error if this timing can not be met with current F_CPU settings.
|
||||
#define w_lowtime ((w1_nops + w_fixedlow) * 1000000) / (F_CPU / 1000)
|
||||
@@ -90,18 +98,6 @@ void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds) {
|
||||
# warning "Please consider a higher clockspeed, if possible"
|
||||
#endif
|
||||
|
||||
#if w2 > 0
|
||||
# define w2_nops w2
|
||||
#else
|
||||
# define w2_nops 0
|
||||
#endif
|
||||
|
||||
#if w3 > 0
|
||||
# define w3_nops w3
|
||||
#else
|
||||
# define w3_nops 0
|
||||
#endif
|
||||
|
||||
#define w_nop1 "nop \n\t"
|
||||
#define w_nop2 "rjmp .+0 \n\t"
|
||||
#define w_nop4 w_nop2 w_nop2
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/* Copyright 2018 Jack Humbert
|
||||
* Copyright 2018 Yiancar
|
||||
*
|
||||
* This program is free sofare: you can redistribute it and/or modify
|
||||
* 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 Sofare Foundation, either version 2 of the License, or
|
||||
* 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,
|
||||
@@ -108,7 +108,6 @@ void i2c_init(void);
|
||||
i2c_status_t i2c_start(uint8_t address);
|
||||
i2c_status_t i2c_transmit(uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout);
|
||||
i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout);
|
||||
i2c_status_t i2c_transmit_receive(uint8_t address, uint8_t* tx_body, uint16_t tx_length, uint8_t* rx_body, uint16_t rx_length);
|
||||
i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout);
|
||||
i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
|
||||
void i2c_stop(void);
|
||||
|
||||
@@ -58,7 +58,10 @@
|
||||
# error invalid SELECT_SOFT_SERIAL_SPEED value
|
||||
#endif
|
||||
|
||||
#define TIMEOUT 100
|
||||
#ifndef SERIAL_USART_TIMEOUT
|
||||
# define SERIAL_USART_TIMEOUT 100
|
||||
#endif
|
||||
|
||||
#define HANDSHAKE_MAGIC 7
|
||||
|
||||
static inline msg_t sdWriteHalfDuplex(SerialDriver* driver, uint8_t* data, uint8_t size) {
|
||||
@@ -201,21 +204,28 @@ int soft_serial_transaction(int index) {
|
||||
sdClear(&SERIAL_USART_DRIVER);
|
||||
|
||||
// First chunk is always transaction id
|
||||
<<<<<<< HEAD
|
||||
sdWriteTimeout(&SERIAL_USART_DRIVER, &sstd_index, sizeof(sstd_index), TIME_MS2I(TIMEOUT));
|
||||
|
||||
uint8_t sstd_index_shake = 0xFF;
|
||||
|
||||
// Which we always read back first so that we can error out correctly
|
||||
=======
|
||||
sdWriteTimeout(&SERIAL_USART_DRIVER, &sstd_index, sizeof(sstd_index), TIME_MS2I(SERIAL_USART_TIMEOUT));
|
||||
// - due to the half duplex limitations on return codes, we always have to read *something*
|
||||
// - without the read, write only transactions *always* succeed, even during the boot process where the slave is not ready
|
||||
<<<<<<< HEAD
|
||||
res = sdReadTimeout(&SERIAL_USART_DRIVER, &sstd_index_shake, sizeof(sstd_index_shake), TIME_MS2I(TIMEOUT));
|
||||
=======
|
||||
res = sdReadTimeout(&SERIAL_USART_DRIVER, &sstd_index_shake, sizeof(sstd_index_shake), TIME_MS2I(SERIAL_USART_TIMEOUT));
|
||||
>>>>>>> 0.12.52~1
|
||||
if (res < 0 || (sstd_index_shake != (sstd_index ^ HANDSHAKE_MAGIC))) {
|
||||
dprintf("serial::usart_shake NO_RESPONSE\n");
|
||||
return TRANSACTION_NO_RESPONSE;
|
||||
}
|
||||
|
||||
if (trans->initiator2target_buffer_size) {
|
||||
<<<<<<< HEAD
|
||||
res = sdWriteTimeout(&SERIAL_USART_DRIVER, trans->initiator2target_buffer, trans->initiator2target_buffer_size, TIME_MS2I(TIMEOUT));
|
||||
=======
|
||||
res = sdWriteTimeout(&SERIAL_USART_DRIVER, trans->initiator2target_buffer, trans->initiator2target_buffer_size, TIME_MS2I(SERIAL_USART_TIMEOUT));
|
||||
>>>>>>> 0.12.52~1
|
||||
if (res < 0) {
|
||||
dprintf("serial::usart_transmit NO_RESPONSE\n");
|
||||
return TRANSACTION_NO_RESPONSE;
|
||||
@@ -223,7 +233,11 @@ int soft_serial_transaction(int index) {
|
||||
}
|
||||
|
||||
if (trans->target2initiator_buffer_size) {
|
||||
<<<<<<< HEAD
|
||||
res = sdReadTimeout(&SERIAL_USART_DRIVER, trans->target2initiator_buffer, trans->target2initiator_buffer_size, TIME_MS2I(TIMEOUT));
|
||||
=======
|
||||
res = sdReadTimeout(&SERIAL_USART_DRIVER, trans->target2initiator_buffer, trans->target2initiator_buffer_size, TIME_MS2I(SERIAL_USART_TIMEOUT));
|
||||
>>>>>>> 0.12.52~1
|
||||
if (res < 0) {
|
||||
dprintf("serial::usart_receive NO_RESPONSE\n");
|
||||
return TRANSACTION_NO_RESPONSE;
|
||||
|
||||
50
drivers/chibios/uart.c
Normal file
50
drivers/chibios/uart.c
Normal file
@@ -0,0 +1,50 @@
|
||||
/* Copyright 2021
|
||||
*
|
||||
* 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 3 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "uart.h"
|
||||
|
||||
#include "quantum.h"
|
||||
|
||||
static SerialConfig serialConfig = {SERIAL_DEFAULT_BITRATE, SD1_CR1, SD1_CR2, SD1_CR3};
|
||||
|
||||
void uart_init(uint32_t baud) {
|
||||
static bool is_initialised = false;
|
||||
|
||||
if (!is_initialised) {
|
||||
is_initialised = true;
|
||||
|
||||
serialConfig.speed = baud;
|
||||
|
||||
#if defined(USE_GPIOV1)
|
||||
palSetLineMode(SD1_TX_PIN, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
|
||||
palSetLineMode(SD1_RX_PIN, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
|
||||
#else
|
||||
palSetLineMode(SD1_TX_PIN, PAL_MODE_ALTERNATE(SD1_TX_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
|
||||
palSetLineMode(SD1_RX_PIN, PAL_MODE_ALTERNATE(SD1_RX_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
|
||||
#endif
|
||||
sdStart(&SERIAL_DRIVER, &serialConfig);
|
||||
}
|
||||
}
|
||||
|
||||
void uart_putchar(uint8_t c) { sdPut(&SERIAL_DRIVER, c); }
|
||||
|
||||
uint8_t uart_getchar(void) {
|
||||
msg_t res = sdGet(&SERIAL_DRIVER);
|
||||
|
||||
return (uint8_t)res;
|
||||
}
|
||||
|
||||
bool uart_available(void) { return !sdGetWouldBlock(&SERIAL_DRIVER); }
|
||||
77
drivers/chibios/uart.h
Normal file
77
drivers/chibios/uart.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/* Copyright 2021
|
||||
*
|
||||
* 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 3 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <hal.h>
|
||||
|
||||
#ifndef SERIAL_DRIVER
|
||||
# define SERIAL_DRIVER SD1
|
||||
#endif
|
||||
|
||||
#ifndef SD1_TX_PIN
|
||||
# define SD1_TX_PIN A9
|
||||
#endif
|
||||
|
||||
#ifndef SD1_TX_PAL_MODE
|
||||
# define SD1_TX_PAL_MODE 7
|
||||
#endif
|
||||
|
||||
#ifndef SD1_RX_PIN
|
||||
# define SD1_RX_PIN A10
|
||||
#endif
|
||||
|
||||
#ifndef SD1_RX_PAL_MODE
|
||||
# define SD1_RX_PAL_MODE 7
|
||||
#endif
|
||||
|
||||
#ifndef SD1_CTS_PIN
|
||||
# define SD1_CTS_PIN A11
|
||||
#endif
|
||||
|
||||
#ifndef SD1_CTS_PAL_MODE
|
||||
# define SD1_CTS_PAL_MODE 7
|
||||
#endif
|
||||
|
||||
#ifndef SD1_RTS_PIN
|
||||
# define SD1_RTS_PIN A12
|
||||
#endif
|
||||
|
||||
#ifndef SD1_RTS_PAL_MODE
|
||||
# define SD1_RTS_PAL_MODE 7
|
||||
#endif
|
||||
|
||||
#ifndef SD1_CR1
|
||||
# define SD1_CR1 0
|
||||
#endif
|
||||
|
||||
#ifndef SD1_CR2
|
||||
# define SD1_CR2 0
|
||||
#endif
|
||||
|
||||
#ifndef SD1_CR3
|
||||
# define SD1_CR3 0
|
||||
#endif
|
||||
|
||||
void uart_init(uint32_t baud);
|
||||
|
||||
void uart_putchar(uint8_t c);
|
||||
|
||||
uint8_t uart_getchar(void);
|
||||
|
||||
bool uart_available(void);
|
||||
76
drivers/chibios/usbpd_stm32g4.c
Normal file
76
drivers/chibios/usbpd_stm32g4.c
Normal file
@@ -0,0 +1,76 @@
|
||||
/* Copyright 2021 Nick Brassel (@tzarc)
|
||||
*
|
||||
* 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 <quantum.h>
|
||||
|
||||
#ifndef USBPD_UCPD1_CFG1
|
||||
# define USBPD_UCPD1_CFG1 (UCPD_CFG1_PSC_UCPDCLK_0 | UCPD_CFG1_TRANSWIN_3 | UCPD_CFG1_IFRGAP_4 | UCPD_CFG1_HBITCLKDIV_4)
|
||||
#endif // USBPD_UCPD1_CFG1
|
||||
|
||||
// Initialises the USBPD subsystem
|
||||
__attribute__((weak)) void usbpd_init(void) {
|
||||
// Disable dead-battery signals
|
||||
PWR->CR3 |= PWR_CR3_UCPD_DBDIS;
|
||||
// Enable the clock for the UCPD1 peripheral
|
||||
RCC->APB1ENR2 |= RCC_APB1ENR2_UCPD1EN;
|
||||
|
||||
// Copy the existing value
|
||||
uint32_t CFG1 = UCPD1->CFG1;
|
||||
// Force-disable UCPD1 before configuring
|
||||
CFG1 &= ~UCPD_CFG1_UCPDEN;
|
||||
// Configure UCPD1
|
||||
CFG1 = USBPD_UCPD1_CFG1;
|
||||
// Apply the changes
|
||||
UCPD1->CFG1 = CFG1;
|
||||
// Enable UCPD1
|
||||
UCPD1->CFG1 |= UCPD_CFG1_UCPDEN;
|
||||
|
||||
// Copy the existing value
|
||||
uint32_t CR = UCPD1->CR;
|
||||
// Clear out ANASUBMODE (irrelevant as a sink device)
|
||||
CR &= ~UCPD_CR_ANASUBMODE_Msk;
|
||||
// Advertise our capabilities as a sink, with both CC lines enabled
|
||||
CR |= UCPD_CR_ANAMODE | UCPD_CR_CCENABLE_Msk;
|
||||
// Apply the changes
|
||||
UCPD1->CR = CR;
|
||||
}
|
||||
|
||||
// Gets the current state of the USBPD allowance
|
||||
__attribute__((weak)) usbpd_allowance_t usbpd_get_allowance(void) {
|
||||
uint32_t CR = UCPD1->CR;
|
||||
|
||||
int ucpd_enabled = (UCPD1->CFG1 & UCPD_CFG1_UCPDEN_Msk) >> UCPD_CFG1_UCPDEN_Pos;
|
||||
int anamode = (CR & UCPD_CR_ANAMODE_Msk) >> UCPD_CR_ANAMODE_Pos;
|
||||
int cc_enabled = (CR & UCPD_CR_CCENABLE_Msk) >> UCPD_CR_CCENABLE_Pos;
|
||||
|
||||
if (ucpd_enabled && anamode && cc_enabled) {
|
||||
uint32_t SR = UCPD1->SR;
|
||||
int vstate_cc1 = (SR & UCPD_SR_TYPEC_VSTATE_CC1_Msk) >> UCPD_SR_TYPEC_VSTATE_CC1_Pos;
|
||||
int vstate_cc2 = (SR & UCPD_SR_TYPEC_VSTATE_CC2_Msk) >> UCPD_SR_TYPEC_VSTATE_CC2_Pos;
|
||||
int vstate_max = vstate_cc1 > vstate_cc2 ? vstate_cc1 : vstate_cc2;
|
||||
switch (vstate_max) {
|
||||
case 0:
|
||||
case 1:
|
||||
return USBPD_500MA; // Note that this is 500mA (i.e. max USB 2.0), not 900mA, as we're not using USB 3.1 as a sink device.
|
||||
case 2:
|
||||
return USBPD_1500MA;
|
||||
case 3:
|
||||
return USBPD_3000MA;
|
||||
}
|
||||
}
|
||||
|
||||
return USBPD_500MA;
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
/* Adapted from https://github.com/bigjosh/SimpleNeoPixelDemo/ */
|
||||
|
||||
#ifndef NOP_FUDGE
|
||||
# if defined(STM32F1XX) || defined(STM32F1xx) || defined(STM32F0XX) || defined(STM32F0xx) || defined(STM32F3XX) || defined(STM32F3xx) || defined(STM32L0XX) || defined(STM32L0xx)
|
||||
# if defined(STM32F0XX) || defined(STM32F1XX) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32L0XX)
|
||||
# define NOP_FUDGE 0.4
|
||||
# else
|
||||
# error("NOP_FUDGE configuration required")
|
||||
|
||||
3125
drivers/chibios/wt_rgb_backlight.c
Normal file
3125
drivers/chibios/wt_rgb_backlight.c
Normal file
File diff suppressed because it is too large
Load Diff
115
drivers/chibios/wt_rgb_backlight.h
Normal file
115
drivers/chibios/wt_rgb_backlight.h
Normal file
@@ -0,0 +1,115 @@
|
||||
/* Copyright 2017 Jason Williams (Wilba)
|
||||
*
|
||||
* 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
|
||||
|
||||
#if RGB_BACKLIGHT_ENABLED
|
||||
#else
|
||||
#error rgb_backlight.h included when RGB_BACKLIGHT_ENABLED == 0
|
||||
#endif // RGB_BACKLIGHT_ENABLED
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "quantum/color.h"
|
||||
|
||||
typedef struct PACKED
|
||||
{
|
||||
uint8_t h;
|
||||
uint8_t s;
|
||||
} HS;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
HS color;
|
||||
uint8_t index;
|
||||
} backlight_config_indicator;
|
||||
|
||||
#if defined(RGB_BACKLIGHT_M6_B)
|
||||
#define RGB_BACKLIGHT_CUSTOM_COLORS_COUNT 6
|
||||
#elif defined(RGB_BACKLIGHT_M10_C)
|
||||
#define RGB_BACKLIGHT_CUSTOM_COLORS_COUNT 10
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
bool use_split_backspace:1; // |
|
||||
bool use_split_left_shift:1; // |
|
||||
bool use_split_right_shift:1; // |
|
||||
bool use_7u_spacebar:1; // |
|
||||
bool use_iso_enter:1; // |
|
||||
bool disable_when_usb_suspended:1; // |
|
||||
bool disable_hhkb_blocker_leds:1; // |
|
||||
bool __pad7:1; // 1 byte
|
||||
uint8_t disable_after_timeout; // 1 byte
|
||||
uint8_t brightness; // 1 byte
|
||||
uint8_t effect; // 1 byte
|
||||
uint8_t effect_speed; // 1 byte
|
||||
HS color_1; // 2 bytes
|
||||
HS color_2; // 2 bytes
|
||||
backlight_config_indicator caps_lock_indicator; // 3 bytes
|
||||
backlight_config_indicator layer_1_indicator; // 3 bytes
|
||||
backlight_config_indicator layer_2_indicator; // 3 bytes
|
||||
backlight_config_indicator layer_3_indicator; // 3 bytes
|
||||
uint16_t alphas_mods[5]; // 10 bytes
|
||||
#if defined(RGB_BACKLIGHT_M6_B) || defined(RGB_BACKLIGHT_M10_C)
|
||||
HS custom_color[RGB_BACKLIGHT_CUSTOM_COLORS_COUNT]; // 12 or 20 bytes
|
||||
#endif
|
||||
} backlight_config; // = 31 bytes (M6-B = 43 bytes, M10-C 51 bytes)
|
||||
|
||||
void backlight_config_load(void);
|
||||
void backlight_config_save(void);
|
||||
void backlight_config_set_value( uint8_t *data );
|
||||
void backlight_config_get_value( uint8_t *data );
|
||||
|
||||
void backlight_init_drivers(void);
|
||||
|
||||
void backlight_timer_init(void);
|
||||
void backlight_timer_enable(void);
|
||||
void backlight_timer_disable(void);
|
||||
|
||||
void backlight_set_suspend_state(bool state);
|
||||
void backlight_set_indicator_state(uint8_t state);
|
||||
|
||||
// This should not be called from an interrupt
|
||||
// (eg. from a timer interrupt).
|
||||
// Call this while idle (in between matrix scans).
|
||||
// If the buffer is dirty, it will update the driver with the buffer.
|
||||
void backlight_update_pwm_buffers(void);
|
||||
|
||||
// Handle backlight specific keycodes
|
||||
bool process_record_backlight(uint16_t keycode, keyrecord_t *record);
|
||||
|
||||
void backlight_set_key_hit(uint8_t row, uint8_t col);
|
||||
|
||||
void backlight_effect_increase(void);
|
||||
void backlight_effect_decrease(void);
|
||||
void backlight_effect_speed_increase(void);
|
||||
void backlight_effect_speed_decrease(void);
|
||||
|
||||
void backlight_brightness_increase(void);
|
||||
void backlight_brightness_decrease(void);
|
||||
|
||||
void backlight_color_1_hue_increase(void);
|
||||
void backlight_color_1_hue_decrease(void);
|
||||
void backlight_color_1_sat_increase(void);
|
||||
void backlight_color_1_sat_decrease(void);
|
||||
void backlight_color_2_hue_increase(void);
|
||||
void backlight_color_2_hue_decrease(void);
|
||||
void backlight_color_2_sat_increase(void);
|
||||
void backlight_color_2_sat_decrease(void);
|
||||
|
||||
void backlight_test_led( uint8_t index, bool red, bool green, bool blue );
|
||||
void backlight_debug_led(bool state);
|
||||
43
drivers/chibios/wt_rgb_backlight_api.h
Normal file
43
drivers/chibios/wt_rgb_backlight_api.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/* Copyright 2017 Jason Williams (Wilba)
|
||||
*
|
||||
* 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
|
||||
|
||||
enum wt_rgb_backlight_config_value
|
||||
{
|
||||
id_use_split_backspace = 0x01,
|
||||
id_use_split_left_shift = 0x02,
|
||||
id_use_split_right_shift = 0x03,
|
||||
id_use_7u_spacebar = 0x04,
|
||||
id_use_iso_enter = 0x05,
|
||||
id_disable_hhkb_blocker_leds = 0x06,
|
||||
id_disable_when_usb_suspended = 0x07,
|
||||
id_disable_after_timeout = 0x08,
|
||||
id_brightness = 0x09,
|
||||
id_effect = 0x0A,
|
||||
id_effect_speed = 0x0B,
|
||||
id_color_1 = 0x0C,
|
||||
id_color_2 = 0x0D,
|
||||
id_caps_lock_indicator_color = 0x0E,
|
||||
id_caps_lock_indicator_row_col = 0x0F,
|
||||
id_layer_1_indicator_color = 0x10,
|
||||
id_layer_1_indicator_row_col = 0x11,
|
||||
id_layer_2_indicator_color = 0x12,
|
||||
id_layer_2_indicator_row_col = 0x13,
|
||||
id_layer_3_indicator_color = 0x14,
|
||||
id_layer_3_indicator_row_col = 0x15,
|
||||
id_alphas_mods = 0x16,
|
||||
id_custom_color = 0x17
|
||||
};
|
||||
34
drivers/chibios/wt_rgb_backlight_keycodes.h
Normal file
34
drivers/chibios/wt_rgb_backlight_keycodes.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/* Copyright 2017 Jason Williams (Wilba)
|
||||
*
|
||||
* 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
|
||||
|
||||
// This is hardcoded at 0x5F00 so it's well after keycode value SAFE_RANGE
|
||||
enum wt_rgb_backlight_keycodes {
|
||||
BR_INC = 0x5F00, // backlight brightness increase
|
||||
BR_DEC, // backlight brightness decrease
|
||||
EF_INC, // backlight effect increase
|
||||
EF_DEC, // backlight effect decrease
|
||||
ES_INC,
|
||||
ES_DEC,
|
||||
H1_INC,
|
||||
H1_DEC,
|
||||
S1_INC,
|
||||
S1_DEC,
|
||||
H2_INC,
|
||||
H2_DEC,
|
||||
S2_INC,
|
||||
S2_DEC
|
||||
};
|
||||
@@ -76,3 +76,20 @@ uint8_t pca9555_readPins(uint8_t slave_addr, uint8_t port) {
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
uint16_t pca9555_readAllPins(uint8_t slave_addr) {
|
||||
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
|
||||
|
||||
typedef union {
|
||||
uint8_t u8[2];
|
||||
uint16_t u16;
|
||||
} data16;
|
||||
|
||||
data16 data;
|
||||
|
||||
i2c_status_t ret = i2c_readReg(addr, CMD_INPUT_0, &data.u8[0], sizeof(data), TIMEOUT);
|
||||
if (ret != I2C_STATUS_SUCCESS) {
|
||||
print("pca9555_readAllPins::FAILED\n");
|
||||
}
|
||||
return data.u16;
|
||||
}
|
||||
|
||||
@@ -53,3 +53,5 @@ void pca9555_set_config(uint8_t slave_addr, uint8_t port, uint8_t conf);
|
||||
void pca9555_set_output(uint8_t slave_addr, uint8_t port, uint8_t conf);
|
||||
|
||||
uint8_t pca9555_readPins(uint8_t slave_addr, uint8_t port);
|
||||
|
||||
uint16_t pca9555_readAllPins(uint8_t slave_addr);
|
||||
|
||||
@@ -194,12 +194,12 @@ void haptic_set_mode(uint8_t mode) {
|
||||
}
|
||||
|
||||
void haptic_set_amplitude(uint8_t amp) {
|
||||
haptic_config.amplitude = amp;
|
||||
eeconfig_update_haptic(haptic_config.raw);
|
||||
xprintf("haptic_config.amplitude = %u\n", haptic_config.amplitude);
|
||||
#ifdef DRV2605L
|
||||
DRV_amplitude(amp);
|
||||
#endif
|
||||
haptic_config.amplitude = amp;
|
||||
eeconfig_update_haptic(haptic_config.raw);
|
||||
xprintf("haptic_config.amplitude = %u\n", haptic_config.amplitude);
|
||||
#ifdef DRV2605L
|
||||
DRV_amplitude(amp);
|
||||
#endif
|
||||
}
|
||||
|
||||
void haptic_set_buzz(uint8_t buzz) {
|
||||
@@ -236,21 +236,59 @@ uint8_t haptic_get_dwell(void) {
|
||||
}
|
||||
|
||||
void haptic_enable_continuous(void) {
|
||||
haptic_config.cont = 1;
|
||||
xprintf("haptic_config.cont = %u\n", haptic_config.cont);
|
||||
eeconfig_update_haptic(haptic_config.raw);
|
||||
#ifdef DRV2605L
|
||||
DRV_rtp_init();
|
||||
#endif
|
||||
haptic_config.cont = 1;
|
||||
xprintf("haptic_config.cont = %u\n", haptic_config.cont);
|
||||
eeconfig_update_haptic(haptic_config.raw);
|
||||
#ifdef DRV2605L
|
||||
DRV_rtp_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
void haptic_disable_continuous(void) {
|
||||
haptic_config.cont = 0;
|
||||
xprintf("haptic_config.cont = %u\n", haptic_config.cont);
|
||||
eeconfig_update_haptic(haptic_config.raw);
|
||||
#ifdef DRV2605L
|
||||
DRV_write(DRV_MODE,0x00);
|
||||
#endif
|
||||
haptic_config.cont = 0;
|
||||
xprintf("haptic_config.cont = %u\n", haptic_config.cont);
|
||||
eeconfig_update_haptic(haptic_config.raw);
|
||||
#ifdef DRV2605L
|
||||
DRV_write(DRV_MODE, 0x00);
|
||||
#endif
|
||||
}
|
||||
|
||||
void haptic_toggle_continuous(void) {
|
||||
#ifdef DRV2605L
|
||||
if (haptic_config.cont) {
|
||||
haptic_disable_continuous();
|
||||
} else {
|
||||
haptic_enable_continuous();
|
||||
}
|
||||
eeconfig_update_haptic(haptic_config.raw);
|
||||
#endif
|
||||
}
|
||||
|
||||
void haptic_cont_increase(void) {
|
||||
uint8_t amp = haptic_config.amplitude + 10;
|
||||
if (haptic_config.amplitude >= 120) {
|
||||
amp = 120;
|
||||
}
|
||||
haptic_set_amplitude(amp);
|
||||
}
|
||||
|
||||
void haptic_cont_decrease(void) {
|
||||
uint8_t amp = haptic_config.amplitude - 10;
|
||||
if (haptic_config.amplitude < 20) {
|
||||
amp = 20;
|
||||
}
|
||||
haptic_set_amplitude(amp);
|
||||
}
|
||||
|
||||
void haptic_play(void) {
|
||||
#ifdef DRV2605L
|
||||
uint8_t play_eff = 0;
|
||||
play_eff = haptic_config.mode;
|
||||
DRV_pulse(play_eff);
|
||||
#endif
|
||||
#ifdef SOLENOID_ENABLE
|
||||
solenoid_fire();
|
||||
#endif
|
||||
}
|
||||
|
||||
void haptic_toggle_continuous(void) {
|
||||
@@ -294,7 +332,6 @@ void haptic_play(void) {
|
||||
}
|
||||
|
||||
bool process_haptic(uint16_t keycode, keyrecord_t *record) {
|
||||
|
||||
if (keycode == HPT_ON && record->event.pressed) {
|
||||
haptic_enable();
|
||||
}
|
||||
@@ -325,16 +362,16 @@ bool process_haptic(uint16_t keycode, keyrecord_t *record) {
|
||||
if (keycode == HPT_DWLD && record->event.pressed) {
|
||||
haptic_dwell_decrease();
|
||||
}
|
||||
if (keycode == HPT_CONT && record->event.pressed) {
|
||||
haptic_toggle_continuous();
|
||||
if (keycode == HPT_CONT && record->event.pressed) {
|
||||
haptic_toggle_continuous();
|
||||
}
|
||||
if (keycode == HPT_CONI && record->event.pressed) {
|
||||
haptic_cont_increase();
|
||||
if (keycode == HPT_CONI && record->event.pressed) {
|
||||
haptic_cont_increase();
|
||||
}
|
||||
if (keycode == HPT_COND && record->event.pressed) {
|
||||
haptic_cont_decrease();
|
||||
if (keycode == HPT_COND && record->event.pressed) {
|
||||
haptic_cont_decrease();
|
||||
}
|
||||
|
||||
|
||||
if (haptic_config.enable) {
|
||||
if (record->event.pressed) {
|
||||
// keypress
|
||||
|
||||
@@ -34,14 +34,14 @@
|
||||
typedef union {
|
||||
uint32_t raw;
|
||||
struct {
|
||||
bool enable :1;
|
||||
uint8_t feedback :2;
|
||||
uint8_t mode :7;
|
||||
bool buzz :1;
|
||||
uint8_t dwell :7;
|
||||
bool cont :1;
|
||||
uint8_t amplitude :8;
|
||||
uint16_t reserved :7;
|
||||
bool enable : 1;
|
||||
uint8_t feedback : 2;
|
||||
uint8_t mode : 7;
|
||||
bool buzz : 1;
|
||||
uint8_t dwell : 7;
|
||||
bool cont : 1;
|
||||
uint8_t amplitude : 8;
|
||||
uint8_t reserved : 5;
|
||||
};
|
||||
} haptic_config_t;
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ void IS31FL3731_init(uint8_t addr) {
|
||||
}
|
||||
|
||||
void IS31FL3731_set_value(int index, uint8_t value) {
|
||||
if (index >= 0 && index < LED_DRIVER_LED_COUNT) {
|
||||
if (index >= 0 && index < DRIVER_LED_TOTAL) {
|
||||
is31_led led = g_is31_leds[index];
|
||||
|
||||
// Subtract 0x24 to get the second index of g_pwm_buffer
|
||||
@@ -196,7 +196,7 @@ void IS31FL3731_set_value(int index, uint8_t value) {
|
||||
}
|
||||
|
||||
void IS31FL3731_set_value_all(uint8_t value) {
|
||||
for (int i = 0; i < LED_DRIVER_LED_COUNT; i++) {
|
||||
for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
|
||||
IS31FL3731_set_value(i, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ typedef struct is31_led {
|
||||
uint8_t v;
|
||||
} __attribute__((packed)) is31_led;
|
||||
|
||||
extern const is31_led g_is31_leds[LED_DRIVER_LED_COUNT];
|
||||
extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
|
||||
|
||||
void IS31FL3731_init(uint8_t addr);
|
||||
void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data);
|
||||
|
||||
45
drivers/oled/licenses.txt
Normal file
45
drivers/oled/licenses.txt
Normal file
@@ -0,0 +1,45 @@
|
||||
The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.
|
||||
|
||||
|
||||
This is the Linux-penguin again...
|
||||
|
||||
Originally drewn by Larry Ewing (http://www.isc.tamu.edu/~lewing/)
|
||||
(with the GIMP) the Linux Logo has been vectorized by me (Simon Budig,
|
||||
http://www.home.unix-ag.org/simon/).
|
||||
|
||||
This happened quite some time ago with Corel Draw 4. But luckily
|
||||
meanwhile there are tools available to handle vector graphics with
|
||||
Linux. Bernhard Herzog (bernhard@users.sourceforge.net) deserves kudos
|
||||
for creating Sketch (http://sketch.sourceforge.net), a powerful free
|
||||
tool for creating vector graphics. He converted the Corel Draw file to
|
||||
the Sketch native format. Since I am unable to maintain the Corel Draw
|
||||
file any longer, the Sketch version now is the "official" one.
|
||||
|
||||
Anja Gerwinski (anja@gerwinski.de) has created an alternate version of
|
||||
the penguin (penguin-variant.sk) with a thinner mouth line and slightly
|
||||
altered gradients. It also features a nifty drop shadow.
|
||||
|
||||
The third bird (penguin-flat.sk) is a version reduced to three colors
|
||||
(black/white/yellow) for e.g. silk screen printing. I made this version
|
||||
for a mug, available at the friendly folks at
|
||||
http://www.kernelconcepts.de/ - they do good stuff, mail Petra
|
||||
(pinguin@kernelconcepts.de) if you need something special or don't
|
||||
understand the german :-)
|
||||
|
||||
These drawings are copyrighted by Larry Ewing and Simon Budig
|
||||
(penguin-variant.sk also by Anja Gerwinski), redistribution is free but
|
||||
has to include this README/Copyright notice.
|
||||
|
||||
The use of these drawings is free. However I am happy about a sample of
|
||||
your mug/t-shirt/whatever with this penguin on it...
|
||||
|
||||
Have fun
|
||||
Simon Budig
|
||||
|
||||
|
||||
Simon.Budig@unix-ag.org
|
||||
http://www.home.unix-ag.org/simon/
|
||||
|
||||
Simon Budig
|
||||
Am Hardtkoeppel 2
|
||||
D-61279 Graevenwiesbach
|
||||
@@ -173,12 +173,12 @@ typedef enum {
|
||||
|
||||
// Initialize the oled display, rotating the rendered output based on the define passed in.
|
||||
// Returns true if the OLED was initialized successfully
|
||||
bool oled_init(uint8_t rotation);
|
||||
bool oled_init(oled_rotation_t rotation);
|
||||
|
||||
// Called at the start of oled_init, weak function overridable by the user
|
||||
// rotation - the value passed into oled_init
|
||||
// Return new uint8_t if you want to override default rotation
|
||||
uint8_t oled_init_user(uint8_t rotation);
|
||||
// Return new oled_rotation_t if you want to override default rotation
|
||||
oled_rotation_t oled_init_user(oled_rotation_t rotation);
|
||||
|
||||
// Clears the display buffer, resets cursor position to 0, and sets the buffer to dirty for rendering
|
||||
void oled_clear(void);
|
||||
|
||||
@@ -206,6 +206,8 @@ void clear_screen(void) {
|
||||
send_data(0);
|
||||
}
|
||||
}
|
||||
|
||||
memset(micro_oled_screen_current, 0, LCDWIDTH * LCDHEIGHT / 8);
|
||||
}
|
||||
|
||||
/** \brief Clear SSD1306's memory.
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
ifneq ($(strip $(QWIIC_ENABLE)),)
|
||||
ifeq ($(strip $(QWIIC_ENABLE)),yes)
|
||||
COMMON_VPATH += $(DRIVER_PATH)/qwiic
|
||||
OPT_DEFS += -DQWIIC_ENABLE
|
||||
SRC += qwiic.c
|
||||
QUANTUM_LIB_SRC += i2c_master.c
|
||||
endif
|
||||
|
||||
ifneq ($(filter JOYSTIIC, $(QWIIC_ENABLE)),)
|
||||
ifneq ($(filter JOYSTIIC, $(QWIIC_DRIVERS)),)
|
||||
OPT_DEFS += -DQWIIC_JOYSTIIC_ENABLE
|
||||
SRC += joystiic.c
|
||||
endif
|
||||
|
||||
ifneq ($(filter MICRO_OLED, $(QWIIC_ENABLE)),)
|
||||
ifneq ($(filter MICRO_OLED, $(QWIIC_DRIVERS)),)
|
||||
OPT_DEFS += -DQWIIC_MICRO_OLED_ENABLE
|
||||
SRC += micro_oled.c
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
29
drivers/usbpd.h
Normal file
29
drivers/usbpd.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/* Copyright 2021 Nick Brassel (@tzarc)
|
||||
*
|
||||
* 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
|
||||
|
||||
typedef enum {
|
||||
USBPD_500MA,
|
||||
USBPD_1500MA,
|
||||
USBPD_3000MA,
|
||||
} usbpd_allowance_t;
|
||||
|
||||
// Initialises the USBPD subsystem
|
||||
void usbpd_init(void);
|
||||
|
||||
// Gets the current state of the USBPD allowance
|
||||
usbpd_allowance_t usbpd_get_allowance(void);
|
||||
Reference in New Issue
Block a user