tetris/sound-driver/spi_init.c

40 lines
733 B
C
Raw Permalink Normal View History

2024-04-17 15:30:45 +02:00
#include <stddef.h>
#include <msp430g2553.h>
#include <stdint.h>
#include "scheduler.h"
#include "spi.h"
#include "soundCodes.h"
2024-05-21 12:31:55 +02:00
#include "config.h"
2024-04-17 15:30:45 +02:00
2024-05-21 12:31:55 +02:00
volatile uint8_t cmd;
2024-04-17 15:30:45 +02:00
void spiInit() {
// SPI slave
// BIT4: UCB0STE
// BIT5: UCB0CLK
// BIT6: UCB0SOMI
// BIT7: UCB0SIMO
P1SEL |= BIT4 | BIT5 | BIT7;
P1SEL2 |= BIT4 | BIT5 | BIT7;
// most significant bit first, enable STE
2024-04-19 11:38:32 +02:00
UCB0CTL0 = UCCKPH | UCSYNC | UCMSB | UCMODE_2;
2024-04-17 15:30:45 +02:00
UCB0CTL1 = 0x00;
// enable RX interrupt
UC0IE |= UCB0RXIE;
cmd = SOUND_IDLE;
2024-05-21 12:31:55 +02:00
schAdd(spiCmdHandler, NULL, 0, 5);
2024-04-17 15:30:45 +02:00
}
2024-05-21 12:31:55 +02:00
void spiCommandDispatcher() {
cmd &= ~SOUND_COMMAND;
2024-04-17 15:30:45 +02:00
2024-05-21 12:31:55 +02:00
if (cmd & SOUND_SUBCMD_AMPLITUDE) {
cmd &= ~SOUND_SUBCMD_AMPLITUDE;
configSetAmplitude(cmd);
}
}