initial commit

This commit is contained in:
matthias@rpi 2023-10-30 22:23:12 +01:00
commit bb0fdeff66
4 changed files with 96 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
spi

22
.vimspector.json Normal file
View File

@ -0,0 +1,22 @@
{
"configurations": {
"spi": {
"adapter": "vscode-cpptools",
"configuration": {
"name": "spi (cpp)",
"type": "cppdbg",
"request": "launch",
"externalConsole": true,
"logging": {
"engineLogging": true
},
"stopOnEntry": true,
"stopAtEntry": true,
"debugOptions": [],
"MIMode": "gdb",
"cwd": "~/6502/spi/",
"program": "./spi"
}
}
}
}

19
Makefile Normal file
View File

@ -0,0 +1,19 @@
CFLAGS = -g -std=c++20 -O2 -DBCM2835_HAVE_LIBCAP
LFLAGS = -lbcm2835
TARGET = spi
default: $(TARGET)
.PHONY = clean
%: %.cpp
g++ $< -o $@ $(CFLAGS) $(LFLAGS)
run: default
sudo ./$(TARGET)
clean:
rm $(TARGET)

54
spi.cpp Normal file
View File

@ -0,0 +1,54 @@
#include <bcm2835.h>
#include <iostream>
#include <string>
#include <thread>
#include <vector>
#define BCM2835
int main(int argc, const char** argv) {
if (bcm2835_init() != 1) {
printf("Error: Could not initalise gpio libraray\n");
return 1;
}
if (bcm2835_spi_begin() != 1) {
printf("Error: Could not begin SPI mode. You might need this: https://www.airspayce.com/mikem/bcm2835/ \"Running as root\"\n");
return 1;
}
/* if (argc != 2) { */
/* printf("Error: Expected exactly one argument (filename), got %d\n", argc); */
/* return 1; */
/* } */
bcm2835_spi_chipSelect(BCM2835_SPI_CS0);
/* bcm2835_spi_set_speed_hz(5); */
bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_65536);
bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::string send = "Hello 6502!";
/* char send[] = "Hello 6502!"; */
std::vector<char> buffer;
buffer.reserve(send.size());
for (char c : send) {
std::cout << c << std::endl;
buffer.push_back(c);
}
/* for (char i = 0; i < 8; i++) { */
/* buffer.push_back(i); */
/* } */
/* buffer.push_back(0b10110101); */
bcm2835_spi_transfern(buffer.data(), buffer.size());
/* std::jthread eepromT(simulateEEPROM, bytes); */
/* std::atomic<CurrentState> cs; */
/* std::jthread clockT(printBusWithClock, PHI2, std::ref(cs)); */
/* /1* auto handler = std::bind(signalHandler, std::placeholders::_1, std::move(eepromT)); *1/ */
/* signal(SIGINT, signalHandler); */
bcm2835_spi_end();
}