Separating the SPI Asynch Class and syntax / documentation questions

Hi,

I am fairly new to MBedOS :pensive:
I have the SPI Asynch example running on my STM32F429 pcb

but I cannot separate the class structure from the app_start

  1. How can I save the SPI_Asynch class in a separate file, away from the app_startā€¦

The code from the example is shown below, but I have several questions about the syntax.

  1. Why does this class use the namespace minar ?

  2. where can I see some documentation for the declaration and this usage ?
    <>
    spi.transfer()
    .tx(tx_buf, SHORT_XFR)
    .rx(rx_buf, SHORT_XFR)
    .callback(SPI::event_callback_t(this, &SPITest::short_transfer_complete_cb), SPI_EVENT_COMPLETE)
    .apply());
    <
    >

I understand how to adjust the SPI pins for my PCB (yotta_targets\stm32f429i-disco-gcc\target.json) but
4. where are these declarations ?
YOTTA_CFG_HARDWARE_TEST_PINS_SPI_MOSI

  1. where can I find the documentation that describes ā€œthisā€ in the eventcallback

  2. is thisScheduled callback FunctionPointer0 limited to a single class ? mbed::util ?? ( I am new to this)
    <>
    Scheduler::postCallback(mbed::util::FunctionPointer0(&test, &SPITest::start).bind());
    <
    >

SPI_Asynch example works unadjusted;
<>

using namespace minar;
class SPITest {
public:
SPITest(): spi(YOTTA_CFG_HARDWARE_TEST_PINS_SPI_MOSI, YOTTA_CFG_HARDWARE_TEST_PINS_SPI_MISO,
YOTTA_CFG_HARDWARE_TEST_PINS_SPI_SCLK), cs(YOTTA_CFG_HARDWARE_TEST_PINS_SPI_SSEL) {
for (uint32_t i = 0; i < sizeof(tx_buf); i++) {
tx_buf[i] = i + TEST_BYTE_TX_BASE;
}
cs = 1;
}

void start() {
    printf("Starting short transfer test\r\n");
    init_rx_buffer();
    cs = 0;
    printf("Result is %d\r\n", spi.transfer()
        .tx(tx_buf, SHORT_XFR)
        .rx(rx_buf, SHORT_XFR)
        .callback(SPI::event_callback_t(this, &SPITest::short_transfer_complete_cb), SPI_EVENT_COMPLETE)
        .apply());
}

private:
void init_rx_buffer() {
. . . . .
<
>

The docs for SPI is part of the API: mbed-drivers/SPI.h at master Ā· ARMmbed/mbed-drivers Ā· GitHub

Drivers are defined within mbed namespace. Minar is another component which has own namespace. SPI for instance is using minar to post callbacks.

1 Like