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

Drivers #26

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
71 changes: 54 additions & 17 deletions software/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(CMAKE_CXX_STANDARD 20)
# debug generated makefile
#set(CMAKE_VERBOSE_MAKEFILE TRUE)

message("*** COMPILER ${CMAKE_CXX_COMPILER_ID}")
message("*** TYPE ${CMAKE_BUILD_TYPE}")
message("*** PLATFORM ${PLATFORM}")
message("*** BOARD ${BOARD}")
Expand All @@ -25,8 +26,13 @@ if("Linux" IN_LIST PLATFORM)
set(LINUX 1)
endif()

# windows
if("Windows" IN_LIST PLATFORM)
set(WINDOWS 1)
endif()

# posix compatible platforms
if(LINUX OR "Macos" IN_LIST PLATFORM OR "FreeBSD" IN_LIST PLATFORM)
if(LINUX OR WINDOWS OR "Macos" IN_LIST PLATFORM OR "FreeBSD" IN_LIST PLATFORM)
set(POSIX 1)
endif()

Expand Down Expand Up @@ -82,13 +88,16 @@ if(POSIX)
Ogg::ogg
gtest::gtest
)
if(WINDOWS)
set(LIBRARIES ${LIBRARIES} wsock32 ws2_32 winmm)
endif()

# enable address sanitizer
if(CMAKE_BUILD_TYPE STREQUAL Debug)
message("Enable Address Sanitizer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
endif()
#if(CMAKE_BUILD_TYPE STREQUAL Debug)
# message("Enable Address Sanitizer")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
#endif()

# set rpath so that shared libraries are searched in ../lib
if(APPLE)
Expand Down Expand Up @@ -149,6 +158,9 @@ endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# clang
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines-ts -Wno-user-defined-literals")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
# visual studio
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4455")
else()
# gcc
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines -fconcepts -Wno-literal-suffix")
Expand Down Expand Up @@ -246,7 +258,13 @@ if(POSIX)
system/src/posix/FlashImpl.hpp
system/src/posix/FlashImpl.cpp
)
set(LOOP system/src/Loop.hpp system/src/posix/Loop.cpp system/src/posix/Loop2.cpp)
set(LOOP
system/src/SystemTime.hpp
system/src/Loop.hpp
system/src/posix/Loop.hpp
system/src/posix/Loop.inc.hpp
system/src/posix/Loop.cpp
)
set(NETWORK system/src/Network.hpp system/src/posix/Network.cpp)
set(OUTPUT system/src/Output.hpp system/src/posix/Output.cpp system/src/Debug.hpp)
set(SOUND system/src/Sound.hpp system/src/posix/Sound.cpp)
Expand All @@ -263,7 +281,12 @@ if(POSIX)
system/src/posix/StorageImpl.cpp
)
set(TERMINAL system/src/Terminal.hpp system/src/posix/Terminal.cpp)
set(TIMER system/src/SystemTime.hpp system/src/Timer.hpp system/src/posix/Timer.cpp)
set(USB_DEVICE
system/src/UsbDevice.hpp
system/src/UsbDevice.cpp
system/src/posix/UsbDeviceImpl.hpp
system/src/posix/UsbDeviceImpl.cpp
)
endif()
if(LINUX)
if(TARGET PkgConfig::BlueZ)
Expand All @@ -285,9 +308,10 @@ if(EMU)
)
set(INPUT system/src/Input.hpp system/src/emu/Input.hpp system/src/emu/Input.cpp)
set(LOOP
system/src/SystemTime.hpp
system/src/Loop.hpp
system/src/posix/Loop.hpp
system/src/posix/Loop.cpp
system/src/posix/Loop.inc.hpp
system/src/emu/Loop.hpp
system/src/emu/Loop.cpp
system/src/emu/Gui.cpp
Expand All @@ -310,6 +334,8 @@ if(EMU)
set(SPI_MASTER
system/src/SpiMaster.hpp
system/src/SpiMaster.cpp
system/src/posix/SpiMasterImpl.hpp
system/src/posix/SpiMasterImpl.cpp
system/src/emu/SpiBME680.hpp
system/src/emu/SpiBME680.cpp
system/src/emu/SpiMPQ6526.hpp
Expand All @@ -319,7 +345,6 @@ if(EMU)
system/src/emu/SpiSSD1309.hpp
system/src/emu/SpiSSD1309.cpp
)
set(USB_DEVICE system/src/UsbDevice.hpp system/src/emu/UsbDevice.cpp)
endif()
if("nrf52" IN_LIST PLATFORM)
set(BUS_MASTER
Expand All @@ -337,7 +362,9 @@ if("nrf52" IN_LIST PLATFORM)
)
set(INPUT system/src/Input.hpp system/src/nrf52/Input.cpp)
set(LOOP
system/src/Loop.hpp system/src/nrf52/Loop.hpp
system/src/SystemTime.hpp
system/src/Loop.hpp
system/src/nrf52/Loop.hpp
system/src/nrf52/Loop.cpp
system/src/nrf52/system/gcc_startup_nrf52840.S
#system/src/nrf52/system/system_nrf52840.c
Expand All @@ -362,8 +389,12 @@ if("nrf52" IN_LIST PLATFORM)
system/src/Storage.cpp
)
set(TERMINAL system/src/Terminal.hpp system/src/nrf52/Terminal.cpp)
set(TIMER system/src/SystemTime.hpp system/src/Timer.hpp system/src/nrf52/Timer.cpp)
set(USB_DEVICE system/src/UsbDevice.hpp system/src/nrf52/UsbDevice.cpp)
set(USB_DEVICE
system/src/UsbDevice.hpp
system/src/UsbDevice.cpp
system/src/nrf52/UsbDeviceImpl.hpp
system/src/nrf52/UsbDeviceImpl.cpp
)
endif()
if("stm32f0" IN_LIST PLATFORM)
set(BUS_NODE
Expand All @@ -380,25 +411,28 @@ if("stm32f0" IN_LIST PLATFORM)
)
set(INPUT system/src/Input.hpp system/src/stm32f0/gpio.hpp system/src/stm32f0/Input.cpp)
set(LOOP
system/src/SystemTime.hpp
system/src/Loop.hpp
system/src/stm32f0/defs.hpp
system/src/stm32f0/Loop.hpp
system/src/stm32f0/Loop.cpp
system/src/stm32f0/system/startup_stm32f042x6.s
#system/src/stm32f0/system/startup_stm32f051x8.s
)
set(OUTPUT system/src/Output.hpp system/src/stm32f0/Output.cpp system/src/Debug.hpp)
set(SPI_MASTER
system/src/SpiMaster.hpp
system/src/SpiMaster.cpp
system/src/stm32f0/SpiMasterImpl.hpp
system/src/stm32f0/SpiMasterImpl.cpp
#system/src/stm32f0/SpiMasterSingle16.hpp
#system/src/stm32f0/SpiMasterSingle16.cpp
)
set(STORAGE
system/src/Storage.hpp
system/src/Storage.cpp
)
set(TERMINAL system/src/Terminal.hpp system/src/stm32f0/Terminal.cpp)
set(TIMER system/src/SystemTime.hpp system/src/Timer.hpp system/src/stm32f0/Timer.cpp)
endif()

set(SYSTEM
Expand All @@ -418,7 +452,6 @@ set(SYSTEM
${SPI_MASTER}
${STORAGE}
${TERMINAL}
${TIMER}
${USB_DEVICE}
system/src/FeRamStorage4.cpp
system/src/FeRamStorage4.hpp
Expand Down Expand Up @@ -664,17 +697,18 @@ endfunction()

add_system_test_executable(Ble)
add_system_test_executable(BusMaster)
add_system_test_executable(BusNode)
add_system_test_executable(Calendar)
add_system_test_executable(Flash)
add_system_test_executable(Input)
add_system_test_executable(Loop)
add_system_test_executable(Network)
add_system_test_executable(QuadratureDecoder)
add_system_test_executable(Radio)
add_system_test_executable(Random)
add_system_test_executable(Sound)
add_system_test_executable(SpiMaster)
add_system_test_executable(Storage)
add_system_test_executable(Timer)
add_system_test_executable(UsbDevice)


Expand Down Expand Up @@ -752,7 +786,7 @@ target_link_libraries(MqttSnBrokerTest ${LIBRARIES})
endif() # POSIX AND NOT EMU


if(${BOARD} STREQUAL "emuControl")
if(${BOARD} STREQUAL "None")

# test for BME680 air sensor
add_executable(BME680Test
Expand All @@ -778,6 +812,9 @@ target_include_directories(BME680Test
)
target_link_libraries(BME680Test ${LIBRARIES})

endif()

if(${BOARD} STREQUAL "emuControl")

# test for SSD1309 display
add_executable(SSD1309Test
Expand Down
7 changes: 7 additions & 0 deletions software/board/None/boardConfig.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <posix/SpiMasterImpl.hpp>
#include <posix/StorageImpl.hpp>
#include <posix/FlashImpl.hpp>
#include <posix/UsbDeviceImpl.hpp>
#include <FlashStorage.hpp>


Expand Down Expand Up @@ -33,6 +34,12 @@ struct Drivers {
FlashStorage storage{flash};
};

struct DriversSpiMasterTest {
SpiMasterImpl transfer{"transfer"};
SpiMasterImpl command{"command"};
SpiMasterImpl data{"data"};
};

struct DriversFlashTest {
FlashImpl flash{"flashTest.bin", 2, 4096, 4};
};
Expand Down
20 changes: 19 additions & 1 deletion software/board/emuControl/boardConfig.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#pragma once

#include <emu/BusMasterImpl.hpp>
#include <emu/BusNodeImpl.hpp>
#include <emu/QuadratureDecoderImpl.hpp>
#include <emu/SpiBME680.hpp>
#include <emu/SpiSSD1309.hpp>
#include <emu/SpiMR45Vxxx.hpp>
#include <posix/SpiMasterImpl.hpp>
#include <posix/StorageImpl.hpp>
#include <posix/FlashImpl.hpp>
#include <posix/UsbDeviceImpl.hpp>
#include <FeRamStorage4.hpp>
#include <FlashStorage.hpp>
#include <util.hpp>
Expand Down Expand Up @@ -60,7 +63,8 @@ constexpr int DISPLAY_HEIGHT = 64;

struct Drivers {
SpiBME680 airSensor;
SpiSSD1309 display{DISPLAY_WIDTH, DISPLAY_HEIGHT};
SpiSSD1309 displayCommand{DISPLAY_WIDTH, DISPLAY_HEIGHT};
SpiSSD1309::Data displayData{displayCommand};
QuadratureDecoderImpl quadratureDecoder;

BusMasterImpl busMaster;
Expand All @@ -74,6 +78,20 @@ struct Drivers {
FeRamStorage4<FERAM_SIZE> counters{feRam};
};

struct DriversSpiMasterTest {
SpiMasterImpl transfer{"transfer"};
SpiMasterImpl command{"command"};
SpiMasterImpl data{"data"};
};

struct DriversBusMasterTest {
BusMasterImpl busMaster;
};

struct DriversBusNodeTest {
BusNodeImpl busNode;
};

struct DriversFlashTest {
FlashImpl flash{"flashTest.bin", 2, 4096, 4};
};
Expand Down
16 changes: 16 additions & 0 deletions software/board/emuSwitch/boardConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#include <emu/SpiBME680.hpp>
#include <emu/SpiSSD1309.hpp>
#include <emu/SpiMPQ6526.hpp>
#include <posix/SpiMasterImpl.hpp>
#include <posix/StorageImpl.hpp>
#include <posix/FlashImpl.hpp>
#include <posix/UsbDeviceImpl.hpp>
#include <FlashStorage.hpp>
#include <util.hpp>

Expand Down Expand Up @@ -78,6 +80,20 @@ struct SwitchDrivers {
StorageImpl counters{"switchCounters.bin", 0xff, 4};
};

struct DriversSpiMasterTest {
SpiMasterImpl transfer{"transfer"};
SpiMasterImpl command{"command"};
SpiMasterImpl data{"data"};
};

struct DriversBusMasterTest {
BusMasterImpl busMaster;
};

struct DriversBusNodeTest {
BusNodeImpl busNode;
};

struct DriversFlashTest {
FlashImpl flash{"flashTest.bin", 2, 1024, 4};
};
Expand Down
31 changes: 24 additions & 7 deletions software/board/nrf52Dongle/boardConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <nrf52/BusMasterImpl.hpp>
#include <nrf52/QuadratureDecoderImpl.hpp>
#include <nrf52/SpiMasterImpl.hpp>
#include <nrf52/UsbDeviceImpl.hpp>
#include <nrf52/FlashImpl.hpp>
#include <FlashStorage.hpp>
#include <util.hpp>
Expand Down Expand Up @@ -74,20 +75,36 @@ constexpr int USB_ENDPOINT_COUNT = 3;
// -------

struct Drivers {
SpiMasterImpl spi{3,
SpiMasterImpl spiDevice{
gpio::P0(19),
gpio::P0(20),
gpio::P0(21),
gpio::P0(21)}; // data/command for write-only display, can be same as MISO
SpiMasterImpl::Channel airSensor{spi, gpio::P0(2)};
SpiMasterImpl::Channel display{spi, gpio::P0(3), true};
SpiMasterImpl::Channel feRam{spi, gpio::P0(3)};
SpiMasterImpl::Channel airSensor{spiDevice, gpio::P0(2)};
SpiMasterImpl::Channel displayCommand{spiDevice, gpio::P0(3), SpiMasterImpl::Channel::Mode::COMMAND};
SpiMasterImpl::Channel displayData{spiDevice, gpio::P0(3), SpiMasterImpl::Channel::Mode::DATA};
SpiMasterImpl::Channel feRam{spiDevice, gpio::P0(3)};
QuadratureDecoderImpl quadratureDecoder{gpio::P0(4), gpio::P0(5)};

BusMasterImpl busMaster{gpio::P0(2), gpio::P0(3)};
//BusMasterImpl busMaster{gpio::P0(2), gpio::P0(3)};

FlashImpl flash{0xe0000 - 0x20000, 4, 32768};
FlashStorage storage{flash};
//FlashImpl flash{0xe0000 - 0x20000, 4, 32768};
//FlashStorage storage{flash};
};

struct DriversSpiMasterTest {
SpiMasterImpl spi{
gpio::P0(19), // SCK
gpio::P0(20), // MOSI
gpio::P0(21), // MISO
gpio::P0(21)}; // DC (data/command for write-only display, can be same as MISO)
SpiMasterImpl::Channel transfer{spi, gpio::P0(2)};
SpiMasterImpl::Channel command{spi, gpio::P0(3), SpiMasterImpl::Channel::Mode::COMMAND};
SpiMasterImpl::Channel data{spi, gpio::P0(3), SpiMasterImpl::Channel::Mode::DATA};
};

struct DriversBusMasterTest {
BusMasterImpl busMaster{gpio::P0(2), gpio::P0(3)};;
};

struct DriversFlashTest {
Expand Down
Loading