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

[Keyboard] Add the Lagrange keyboard #11374

Merged
merged 2 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Covert the master side to use the SPI driver.
  • Loading branch information
Dimitris Papavasiliou committed Feb 12, 2021
commit 1ee8ef0a89c9b4c831739c4f020dff2edb9b9296
5 changes: 4 additions & 1 deletion keyboards/handwired/lagrange/lagrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

#include "quantum.h"

#define SPI_SS_PIN B0
#if !defined(SPI_SS_PIN)
# define SPI_SS_PIN B0
#endif

#define SPI_SCK_PIN B1
#define SPI_MOSI_PIN B2
#define SPI_MISO_PIN B3
Expand Down
2 changes: 1 addition & 1 deletion keyboards/handwired/lagrange/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ UNICODE_ENABLE = yes
SPLIT_KEYBOARD = yes
SPLIT_TRANSPORT = custom

SRC += transport.c
SRC += transport.c spi_master.c
28 changes: 20 additions & 8 deletions keyboards/handwired/lagrange/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <spi_master.h>

#include "quantum.h"
#include "split_util.h"
#include "timer.h"
Expand Down Expand Up @@ -78,14 +80,23 @@ bool transport_master(matrix_row_t matrix[]) {
* while transmitting LED and layer states. */

shake_hands(true);
writePinLow(SPI_SS_PIN);

spi_start(SPI_SS_PIN, 0, 0, 4);

for (i = 0 ; i < sizeof(matrix_row_t[MATRIX_ROWS / 2]) ; i += 1) {
((uint8_t *)matrix)[i] = transceive(i < sizeof(struct led_context) ?
((uint8_t *)&context)[i] : 0);
spi_status_t x;

x = spi_write(i < sizeof(struct led_context) ?
((uint8_t *)&context)[i] : 0);

if (x == SPI_STATUS_TIMEOUT) {
return false;
}

((uint8_t *)matrix)[i] = (uint8_t)x;
}

writePinHigh(SPI_SS_PIN);
spi_stop();

return true;
}
Expand Down Expand Up @@ -130,13 +141,14 @@ void transport_slave(matrix_row_t matrix[]) {
}

void transport_master_init(void) {
/* We need to set the SS pin as output as the handshake logic
* above depends on it and the SPI master driver won't do it
* before we call spi_start(). */

writePinHigh(SPI_SS_PIN);
setPinOutput(SPI_SS_PIN);
setPinOutput(SPI_SCK_PIN);
setPinOutput(SPI_MOSI_PIN);
setPinInput(SPI_MISO_PIN);

SPCR = (_BV(SPE) | _BV(MSTR));
spi_init();

shake_hands(true);
}
Expand Down