Skip to content

Commit

Permalink
XT converter cleanup (qmk#12264)
Browse files Browse the repository at this point in the history
  • Loading branch information
fauxpark committed Mar 18, 2021
1 parent a8ab089 commit f743bb1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
39 changes: 21 additions & 18 deletions tmk_core/protocol/xt.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,36 @@ POSSIBILITY OF SUCH DAMAGE.

#pragma once

#define XT_DATA_IN() \
do { \
XT_DATA_DDR &= ~(1 << XT_DATA_BIT); \
XT_DATA_PORT |= (1 << XT_DATA_BIT); \
#include "quantum.h"

#define XT_DATA_IN() \
do { \
setPinInput(XT_DATA_PIN); \
writePinHigh(XT_DATA_PIN); \
} while (0)

#define XT_DATA_READ() (XT_DATA_PIN & (1 << XT_DATA_BIT))
#define XT_DATA_READ() readPin(XT_DATA_PIN)

#define XT_DATA_LO() \
do { \
XT_DATA_PORT &= ~(1 << XT_DATA_BIT); \
XT_DATA_DDR |= (1 << XT_DATA_BIT); \
#define XT_DATA_LO() \
do { \
writePinLow(XT_DATA_PIN); \
setPinOutput(XT_DATA_PIN); \
} while (0)

#define XT_CLOCK_IN() \
do { \
XT_CLOCK_DDR &= ~(1 << XT_CLOCK_BIT); \
XT_CLOCK_PORT |= (1 << XT_CLOCK_BIT); \
#define XT_CLOCK_IN() \
do { \
setPinInput(XT_CLOCK_PIN); \
writePinHigh(XT_CLOCK_PIN); \
} while (0)

#define XT_CLOCK_READ() (XT_CLOCK_PIN & (1 << XT_CLOCK_BIT))
#define XT_CLOCK_READ() readPin(XT_CLOCK_PIN)

#define XT_CLOCK_LO() \
do { \
XT_CLOCK_PORT &= ~(1 << XT_CLOCK_BIT); \
XT_CLOCK_DDR |= (1 << XT_CLOCK_BIT); \
#define XT_CLOCK_LO() \
do { \
writePinLow(XT_CLOCK_PIN); \
setPinOutput(XT_CLOCK_PIN); \
} while (0)

void xt_host_init(void);

uint8_t xt_host_recv(void);
7 changes: 5 additions & 2 deletions tmk_core/protocol/xt_interrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ POSSIBILITY OF SUCH DAMAGE.

#include <stdbool.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "xt.h"
#include "wait.h"
#include "debug.h"
Expand All @@ -60,7 +59,7 @@ void xt_host_init(void) {
/* soft reset: pull clock line down for 20ms */
XT_DATA_LO();
XT_CLOCK_LO();
_delay_ms(20);
wait_ms(20);

/* input mode with pullup */
XT_CLOCK_IN();
Expand Down Expand Up @@ -123,6 +122,7 @@ ISR(XT_INT_VECT) {
static uint8_t pbuf[PBUF_SIZE];
static uint8_t pbuf_head = 0;
static uint8_t pbuf_tail = 0;

static inline void pbuf_enqueue(uint8_t data) {
uint8_t sreg = SREG;
cli();
Expand All @@ -135,6 +135,7 @@ static inline void pbuf_enqueue(uint8_t data) {
}
SREG = sreg;
}

static inline uint8_t pbuf_dequeue(void) {
uint8_t val = 0;

Expand All @@ -148,13 +149,15 @@ static inline uint8_t pbuf_dequeue(void) {

return val;
}

static inline bool pbuf_has_data(void) {
uint8_t sreg = SREG;
cli();
bool has_data = (pbuf_head != pbuf_tail);
SREG = sreg;
return has_data;
}

static inline void pbuf_clear(void) {
uint8_t sreg = SREG;
cli();
Expand Down

0 comments on commit f743bb1

Please sign in to comment.