Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SN74x138 demultiplexer driver #16217

Merged
merged 3 commits into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 65 additions & 0 deletions drivers/gpio/sn74x138.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* Copyright 2022
*
* 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 "sn74x138.h"
#include "gpio.h"

#define ADDRESS_PIN_COUNT 3

#ifndef SN74X138_ADDRESS_PINS
# error sn74x138: no address pins defined!
#endif

static const pin_t address_pins[ADDRESS_PIN_COUNT] = SN74X138_ADDRESS_PINS;

void sn74x138_init(void) {
for (int i = 0; i < ADDRESS_PIN_COUNT; i++) {
setPinOutput(address_pins[i]);
writePinLow(address_pins[i]);
}

#if defined(SN74X138_E1_PIN)
setPinOutput(SN74X138_E1_PIN);
writePinHigh(SN74X138_E1_PIN);
#endif

#if defined(SN74X138_E2_PIN)
setPinOutput(SN74X138_E2_PIN);
writePinHigh(SN74X138_E2_PIN);
#endif
#if defined(SN74X138_E3_PIN)
setPinOutput(SN74X138_E3_PIN);
writePinLow(SN74X138_E3_PIN);
#endif
}

void sn74x138_set_enabled(bool enabled) {
#if defined(SN74X138_E1_PIN)
writePin(SN74X138_E1_PIN, !enabled);
#endif
#if defined(SN74X138_E2_PIN)
writePin(SN74X138_E2_PIN, !enabled);
#endif
#if defined(SN74X138_E3_PIN)
writePin(SN74X138_E3_PIN, enabled);
#endif
}

void sn74x138_set_addr(uint8_t address) {
for (int i = 0; i < ADDRESS_PIN_COUNT; i++) {
writePin(address_pins[i], address & (1 << i));
}
}
48 changes: 48 additions & 0 deletions drivers/gpio/sn74x138.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* Copyright 2022
*
* 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 <stdint.h>
#include <stdbool.h>

/**
* Driver for 74x138 3-to-8 decoder/demultiplexer with inverting outputs
* https://assets.nexperia.com/documents/data-sheet/74HC_HCT138.pdf
*/

/**
* Initialize the address and output enable pins.
*/
void sn74x138_init(void);

/**
* Set the enabled state.
*
* When enabled is true, pulls the E1 and E2 pins low, and the E3 pin high.
*
* \param enabled The enable state to set.
*/
void sn74x138_set_enabled(bool enabled);

/**
* Set the output pin address.
*
* The selected output pin will be pulled low, while the remaining output pins will be high.
*
* \param address The address to set, from 0 to 7.
*/
void sn74x138_set_addr(uint8_t address);
10 changes: 2 additions & 8 deletions keyboards/evyd13/wasdat/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#define MATRIX_ROW_PINS { D6, D4, F6, F7, F4, F5, F0, F1 }
#define MATRIX_COL_PINS { }
#define MATRIX_COL_PINS { C7, B6, C6, B4, B5, D7, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, D3, B7, B3 } // Columns 6-12 controlled by demux
#define UNUSED_PINS

/* COL2ROW, ROW2COL*/
#define DIODE_DIRECTION ROW2COL
#define SN74X138_ADDRESS_PINS { D2, D1, D0 }

// For QMK DFU
#define QMK_ESC_OUTPUT D6
#define QMK_ESC_INPUT D7
#define QMK_LED B0

/*
* Split Keyboard specific options, make sure you have 'SPLIT_KEYBOARD = yes' in your rules.mk, and define SOFT_SERIAL_PIN.
*/
//#define SOFT_SERIAL_PIN D0 // or D1, D2, D3, E6

#define LED_NUM_LOCK_PIN B2
#define LED_CAPS_LOCK_PIN B0
#define LED_SCROLL_LOCK_PIN B1
Expand Down