Skip to content

Commit

Permalink
Fix SPI - odd sequence at end of data: electro-smith#553
Browse files Browse the repository at this point in the history
  • Loading branch information
eh2k committed Jan 8, 2023
1 parent 22b7d43 commit 153f6ed
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
14 changes: 14 additions & 0 deletions examples/OLED_SPI/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Project Name
TARGET = OledSPI

# Sources
CPP_SOURCES = OledSPI.cpp

# Library Locations
LIBDAISY_DIR = ../../

#APP_TYPE = BOOT_SRAM

# Core location, and generic Makefile.
SYSTEM_FILES_DIR = $(LIBDAISY_DIR)/core
include $(SYSTEM_FILES_DIR)/Makefile
81 changes: 81 additions & 0 deletions examples/OLED_SPI/OledSPI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* @author eh2k
* @brief
* @date 2023-01-08
*
* OLED using hardware spi
* Shows how to setup an OLED display on the Daisy Patch SM using hardware spi.
*/

#include "daisy_patch_sm.h"
#include "dev/oled_ssd130x.h"

using namespace daisy;
using namespace patch_sm;

DaisyPatchSM hw;

using namespace daisy;
using namespace daisy::patch_sm;

using MyDisplay = OledDisplay<SSD130x4WireSpi128x64Driver>;
MyDisplay display;

void AudioCallback(AudioHandle::InputBuffer in,
AudioHandle::OutputBuffer out,
size_t size)
{
//
}

int main(void)
{
// Initialize the hardware
hw.Init();
hw.StartAudio(AudioCallback);

MyDisplay::Config display_config;

SpiHandle::Config& spi_conf = display_config.driver_config.transport_config.spi_config;

spi_conf.mode = SpiHandle::Config::Mode::MASTER; // we're in charge
spi_conf.periph = SpiHandle::Config::Peripheral::SPI_2; // Use the SPI_2 Peripheral
spi_conf.direction = SpiHandle::Config::Direction::ONE_LINE; // TWO_LINES_TX_ONLY;

spi_conf.datasize = 8;
spi_conf.clock_polarity = SpiHandle::Config::ClockPolarity::LOW;
spi_conf.clock_phase = SpiHandle::Config::ClockPhase::ONE_EDGE;
// spi_conf.nss = SpiHandle::Config::NSS::HARD_OUTPUT;
spi_conf.baud_prescaler = SpiHandle::Config::BaudPrescaler::PS_128;

// Pins to use. These must be available on the selected peripheral
spi_conf.pin_config.sclk = DaisyPatchSM::D10; // Use pin D10 as SCLK
spi_conf.pin_config.miso = Pin(); // We won't need this
spi_conf.pin_config.mosi = DaisyPatchSM::D9; // Use D9 as MOSI
spi_conf.pin_config.nss = Pin(); // DaisyPatchSM::D1; // use D1 as NSS

// data will flow from master to slave over just the MOSI line

// The master will output on the NSS line
spi_conf.nss = SpiHandle::Config::NSS::SOFT;

display_config.driver_config.transport_config.pin_config.dc
= DaisyPatchSM::D2;
display_config.driver_config.transport_config.pin_config.reset
= DaisyPatchSM::D3;
display.Init(display_config);

char tmp[64];

// loop forever
while(1)
{
ScopedIrqBlocker _;

display.Fill(false);
display.SetCursor(0, 0);
sprintf(tmp, "%d", System::GetUs());
display.WriteString(tmp, Font_6x8, true);
display.Update();
}
}
2 changes: 1 addition & 1 deletion src/per/spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ SpiHandle::Result SpiHandle::Impl::Init(const Config& config)
hspi_.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
hspi_.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
hspi_.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
hspi_.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
hspi_.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_ENABLE;
hspi_.Init.IOSwap = SPI_IO_SWAP_DISABLE;
if(HAL_SPI_Init(&hspi_) != HAL_OK)
{
Expand Down

0 comments on commit 153f6ed

Please sign in to comment.