Skip to content

Commit

Permalink
rewrite graphics
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSaw committed Oct 31, 2021
1 parent 79eb43b commit fd926fa
Show file tree
Hide file tree
Showing 193 changed files with 7,765 additions and 15,302 deletions.
2 changes: 1 addition & 1 deletion examples/nucleo_f042k6/spi_dma/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main()
uint8_t receiveBuffer[13];

// send out 12 bytes, don't care about response
Spi::transferBlocking(sendBuffer, nullptr, 12);
Spi::transferBlocking(sendBuffer, (uint8_t*)(nullptr), 12);

// send out 12 bytes, read in 12 bytes
Spi::transferBlocking(sendBuffer, receiveBuffer, 12);
Expand Down
2 changes: 1 addition & 1 deletion examples/nucleo_f303re/spi_dma/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main()
uint8_t receiveBuffer[13];

// send out 12 bytes, don't care about response
Spi::transferBlocking(sendBuffer, nullptr, 12);
Spi::transferBlocking(sendBuffer, (uint8_t*)(nullptr), 12);

// send out 12 bytes, read in 12 bytes
Spi::transferBlocking(sendBuffer, receiveBuffer, 12);
Expand Down
2 changes: 1 addition & 1 deletion examples/nucleo_l432kc/spi_dma/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main()
uint8_t receiveBuffer[13];

// send out 12 bytes, don't care about response
Spi::transferBlocking(sendBuffer, nullptr, 12);
Spi::transferBlocking(sendBuffer, (uint8_t*)(nullptr), 12);

// send out 12 bytes, read in 12 bytes
Spi::transferBlocking(sendBuffer, receiveBuffer, 12);
Expand Down
16 changes: 7 additions & 9 deletions examples/nucleo_l452re/graphics_touch/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace touch
//using Interrupt = modm::platform::GpioA10;
}

modm::Touch2046<touch::Spi, touch::Cs> touchController;
modm::Touch2046<touch::Spi, touch::Cs, 320, 240> touchController;


int
Expand All @@ -75,12 +75,10 @@ main()
touch::Mosi::Mosi>();
touch::Spi::initialize<SystemClock, 2500_kHz>();
modm::touch2046::Calibration cal{
.OffsetX = -11,
.OffsetY = 335,
.FactorX = 22018,
.OffsetX = -11,
.FactorY = -29358,
.MaxX = 240,
.MaxY = 320,
.OffsetY = 335,
.ThresholdZ = 500,
};
touchController.setCalibration(cal);
Expand All @@ -107,22 +105,22 @@ main()

int16_t X = 0;
int16_t Y = 0;
int16_t Z = 0;
// int16_t Z = 0;

while (true)
{
LedGreen::set();

std::tie(X, Y, Z) = RF_CALL_BLOCKING(touchController.getRawValues());
std::tie(X, Y) = RF_CALL_BLOCKING(touchController.getTouchPosition());
tftController.setColor(Red);
tftController.fillRectangle({30, 50}, 90, 115);
tftController.setColor(Black);
tftController.setCursor(0, 50);
tftController << "X=" << X;
tftController.setCursor(0, 90);
tftController << "Y=" << Y;
tftController.setCursor(0, 130);
tftController << "Z=" << Z;
// tftController.setCursor(0, 130);
// tftController << "Z=" << Z;

tftController.setColor(Red);
tftController.fillRectangle({30, 220}, 120, 35);
Expand Down
2 changes: 1 addition & 1 deletion examples/nucleo_l452re/lvgl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace touch
//using Interrupt = modm::platform::GpioA10;
}

modm::Touch2046<touch::Spi, touch::Cs> touchController;
modm::Touch2046<touch::Spi, touch::Cs, 320, 240> touchController;


static lv_disp_draw_buf_t disp_buf;
Expand Down
2 changes: 1 addition & 1 deletion src/modm/architecture/interface/accessor_flash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Flash
return address;
}

private:
protected:
const T* address;
#if MODM_HAS_IOSTREAM
private:
Expand Down
2 changes: 1 addition & 1 deletion src/modm/architecture/interface/accessor_ram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Ram
return address;
}

private:
protected:
const T* address;
};

Expand Down
53 changes: 45 additions & 8 deletions src/modm/architecture/interface/spi_master.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright (c) 2010, Martin Rosekeit
* Copyright (c) 2012-2017, Niklas Hauser
* Copyright (c) 2013, Sascha Schade
* Copyright (c) 2021, Thomas Sommer
*
* This file is part of the modm project.
*
Expand Down Expand Up @@ -96,14 +97,28 @@ class SpiMaster : public ::modm::PeripheralDriver, public Spi
release(void *ctx);

/**
* Swap a single byte and wait for completion.
* Swap a single byte or word or word and wait for completion.
*
* @param data
* data to be sent
* @return received data
*/
static uint8_t
transferBlocking(uint8_t data);
template <std::unsigned_integral T>
static T
transferBlocking(T data);

/**
* Swap a single byte or word or word multiple times and wait for completion non-blocking!
* This may be hardware accelerated (DMA or Interrupt), but not guaranteed.
*
* @param[in] tx
* pointer to transmit data
* @param repeat
* number of repetitions for same byte or word or word
*/
template <std::unsigned_integral T>
static modm::ResumableResult<void>
transfer(const T *tx, const std::size_t repeat);

/**
* Set the data buffers and length with options and starts a transfer.
Expand All @@ -116,11 +131,12 @@ class SpiMaster : public ::modm::PeripheralDriver, public Spi
* @param length
* number of bytes to be shifted out
*/
template <std::unsigned_integral T>
static void
transferBlocking(const uint8_t *tx, uint8_t *rx, std::size_t length);
transferBlocking(const T *tx, T *rx, const std::size_t length);

/**
* Swap a single byte and wait for completion non-blocking!.
* Swap a single byte or word and wait for completion non-blocking!
*
* You must call this inside a Protothread or Resumable
* using `PT_CALL` or `RF_CALL` respectively.
Expand All @@ -132,8 +148,28 @@ class SpiMaster : public ::modm::PeripheralDriver, public Spi
* data to be sent
* @return received data
*/
static modm::ResumableResult<uint8_t>
transfer(uint8_t data);
template <std::unsigned_integral T>
static modm::ResumableResult<T>
transfer(T data);

/**
* Swap a single byte or word multiple times and wait for completion non-blocking!
* This may be hardware accelerated (DMA or Interrupt), but not guaranteed.
*
* You must call this inside a Protothread or Resumable
* using `PT_CALL` or `RF_CALL` respectively.
* @warning These methods differ from Resumables by lacking context protection!
* You must ensure that only one driver is accessing this resumable function
* by using `acquire(ctx)` and `release(ctx)`.
*
* @param[in] tx
* pointer to transmit data
* @param repeat
* number of repetitions for same byte or word
*/
template <std::unsigned_integral T>
static modm::ResumableResult<void>
transfer(const T *tx, const std::size_t repeat);

/**
* Set the data buffers and length with options and
Expand All @@ -153,8 +189,9 @@ class SpiMaster : public ::modm::PeripheralDriver, public Spi
* @param length
* number of bytes to be shifted out
*/
template <std::unsigned_integral T>
static modm::ResumableResult<void>
transfer(const uint8_t *tx, uint8_t *rx, std::size_t length);
transfer(const T *tx, T *rx, const std::size_t length);
#endif
};

Expand Down
53 changes: 27 additions & 26 deletions src/modm/driver/can/mcp2515_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,22 @@ modm::Mcp2515<SPI, CS, INT>::initializeWithPrescaler(
// software reset for the mcp2515, after this the chip is back in the
// configuration mode
chipSelect.reset();
spi.transferBlocking(RESET);
spi.transferBlocking(uint8_t(RESET));
modm::delay_ms(1);
chipSelect.set();

// wait a bit to give the MCP2515 some time to restart
modm::delay_ms(30);

chipSelect.reset();
spi.transferBlocking(WRITE);
spi.transferBlocking(CNF3);
spi.transferBlocking(uint8_t(WRITE));
spi.transferBlocking(uint8_t(CNF3));

// load CNF1..3
spi.transferBlocking(cnf, nullptr, 3);
spi.transferBlocking(cnf, (uint8_t*)(nullptr), 3);

// enable interrupts
spi.transferBlocking(RX1IE | RX0IE);
spi.transferBlocking(uint8_t(RX1IE | RX0IE));
chipSelect.set();

// set TXnRTS pins as inwrites
Expand Down Expand Up @@ -146,7 +146,7 @@ modm::Mcp2515<SPI, CS, INT>::setFilter(accessor::Flash<uint8_t> filter)
for (i = 0; i < 0x30; i += 0x10)
{
chipSelect.reset();
spi.transferBlocking(WRITE);
spi.transferBlocking(uint8_t(WRITE));
spi.transferBlocking(i);

for (j = 0; j < 12; j++)
Expand Down Expand Up @@ -222,10 +222,10 @@ modm::Mcp2515<SPI, CS, INT>::getMessage(can::Message& message)
else {
message.flags.rtr = false;
}
message.length = spi.transferBlocking(0xff) & 0x0f;
message.length = spi.transferBlocking(uint8_t(0xff)) & 0x0f;

for (uint8_t i = 0; i < message.length; ++i) {
message.data[i] = spi.transferBlocking(0xff);
message.data[i] = spi.transferBlocking(uint8_t(0xff));
}
chipSelect.set();

Expand Down Expand Up @@ -279,12 +279,12 @@ modm::Mcp2515<SPI, CS, INT>::sendMessage(const can::Message& message)
}

chipSelect.reset();
spi.transferBlocking(WRITE_TX | address);
spi.transferBlocking(uint8_t(WRITE_TX | address));
writeIdentifier(message.identifier, message.flags.extended);

// if the message is a rtr-frame, is has a length but no attached data
if (message.flags.rtr) {
spi.transferBlocking(MCP2515_RTR | message.length);
spi.transferBlocking(uint8_t(MCP2515_RTR | message.length));
}
else {
spi.transferBlocking(message.length);
Expand All @@ -300,7 +300,7 @@ modm::Mcp2515<SPI, CS, INT>::sendMessage(const can::Message& message)
// send message via RTS command
chipSelect.reset();
address = (address == 0) ? 1 : address; // 0 2 4 => 1 2 4
spi.transferBlocking(RTS | address);
spi.transferBlocking(uint8_t(RTS | address));
chipSelect.set();

return address;
Expand All @@ -314,7 +314,7 @@ modm::Mcp2515<SPI, CS, INT>::writeRegister(uint8_t address, uint8_t data)
{
chipSelect.reset();

spi.transferBlocking(WRITE);
spi.transferBlocking(uint8_t(WRITE));
spi.transferBlocking(address);
spi.transferBlocking(data);

Expand All @@ -327,9 +327,9 @@ modm::Mcp2515<SPI, CS, INT>::readRegister(uint8_t address)
{
chipSelect.reset();

spi.transferBlocking(READ);
spi.transferBlocking(uint8_t(READ));
spi.transferBlocking(address);
uint8_t data = spi.transferBlocking(0xff);
uint8_t data = spi.transferBlocking(uint8_t(0xff));

chipSelect.set();

Expand All @@ -342,7 +342,7 @@ modm::Mcp2515<SPI, CS, INT>::bitModify(uint8_t address, uint8_t mask, uint8_t da
{
chipSelect.reset();

spi.transferBlocking(BIT_MODIFY);
spi.transferBlocking(uint8_t(BIT_MODIFY));
spi.transferBlocking(address);
spi.transferBlocking(mask);
spi.transferBlocking(data);
Expand All @@ -357,7 +357,7 @@ modm::Mcp2515<SPI, CS, INT>::readStatus(uint8_t type)
chipSelect.reset();

spi.transferBlocking(type);
uint8_t data = spi.transferBlocking(0xff);
uint8_t data = spi.transferBlocking(uint8_t(0xff));

chipSelect.set();

Expand Down Expand Up @@ -391,10 +391,11 @@ modm::Mcp2515<SPI, CS, INT>::writeIdentifier(const uint32_t& identifier,
}
else
{
spi.transferBlocking(*((uint16_t *) ptr) >> 3);
spi.transferBlocking(*((uint8_t *) ptr) << 5);
spi.transferBlocking(0);
spi.transferBlocking(0);
spi.transferBlocking(uint8_t(*((uint16_t *) ptr) >> 3));
spi.transferBlocking(uint8_t(*((uint8_t *) ptr) << 5));

spi.transferBlocking(uint8_t(0));
spi.transferBlocking(uint8_t(0));
}
}

Expand All @@ -406,31 +407,31 @@ modm::Mcp2515<SPI, CS, INT>::readIdentifier(uint32_t& identifier)

uint32_t *ptr = &identifier;

uint8_t first = spi.transferBlocking(0xff);
uint8_t second = spi.transferBlocking(0xff);
uint8_t first = spi.transferBlocking(uint8_t(0xff));
uint8_t second = spi.transferBlocking(uint8_t(0xff));

if (second & MCP2515_IDE)
{
*((uint16_t *) ptr + 1) = (uint16_t) first << 5;
*((uint8_t *) ptr + 1) = spi.transferBlocking(0xff);
*((uint8_t *) ptr + 1) = spi.transferBlocking(uint8_t(0xff));

*((uint8_t *) ptr + 2) |= (second >> 3) & 0x1C;
*((uint8_t *) ptr + 2) |= second & 0x03;

*((uint8_t *) ptr) = spi.transferBlocking(0xff);
*((uint8_t *) ptr) = spi.transferBlocking(uint8_t(0xff));

return true;
}
else
{
spi.transferBlocking(0xff);
spi.transferBlocking(uint8_t(0xff));

*((uint8_t *) ptr + 3) = 0;
*((uint8_t *) ptr + 2) = 0;

*((uint16_t *) ptr) = (uint16_t) first << 3;

spi.transferBlocking(0xff);
spi.transferBlocking(uint8_t(0xff));

*((uint8_t *) ptr) |= second >> 5;

Expand Down
Loading

0 comments on commit fd926fa

Please sign in to comment.