6502-spi/spi.cpp

55 lines
1.6 KiB
C++
Raw Permalink Normal View History

2023-10-30 22:23:12 +01:00
#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();
}