gat8bitbang

This object uses bitbang method to emulate and transmit SPI messages to Gat8 extension. CS=PA0, SCLK=PB9, MOSI/DIN=PB8 and GND=GND. LED4 of Euxoloti 1.0 can't be used with this object!
Author:
License:
Github: euxo/1 0/gat8bitbang.axo

Inlets

bool32 Go1

bool32 Go2

bool32 Go3

bool32 Go4

bool32 Go5

bool32 Go6

bool32 Go7

bool32 Go8

Outlets

None

Declaration
int32_t Go1, Go2, Go3, Go4, Go5, Go6, Go7, Go8;
uint8_t *gat8buf;

msg_t ThreadX2() {
  static uint8_t _gat8buf[7] __attribute__((section(".sram2")));
  gat8buf = _gat8buf;

  palWritePad(GPIOA, 0, 1);

  while (!chThdShouldTerminate()) {
    // manual SPI bit bang
    if (Go1 == 0) {
      gat8buf[0] = 1;
    } else {
      gat8buf[0] = 0;
    }
    if (Go2 == 0) {
      gat8buf[1] = 1;
    } else {
      gat8buf[1] = 0;
    }
    if (Go3 == 0) {
      gat8buf[2] = 1;
    } else {
      gat8buf[2] = 0;
    }
    if (Go4 == 0) {
      gat8buf[3] = 1;
    } else {
      gat8buf[3] = 0;
    }
    if (Go5 == 0) {
      gat8buf[4] = 1;
    } else {
      gat8buf[4] = 0;
    }
    if (Go6 == 0) {
      gat8buf[5] = 1;
    } else {
      gat8buf[5] = 0;
    }
    if (Go7 == 0) {
      gat8buf[6] = 1;
    } else {
      gat8buf[6] = 0;
    }
    if (Go8 == 0) {
      gat8buf[7] = 1;
    } else {
      gat8buf[7] = 0;
    }

    for (int i = 0; i <= 8; i++) {
      palWritePad(GPIOB, 9, 1);          // clock pin high (SCK)
      palWritePad(GPIOB, 8, gat8buf[i]); // bit state (MOSI)

      chThdSleepMilliseconds(1);
      palWritePad(GPIOB, 9, 0); // clock pin low (SCK)
                                // chThdSleepMilliseconds(1);
    }
    palWritePad(GPIOA, 0, 0); // enable CS
    chThdSleepMilliseconds(1);
    palWritePad(GPIOA, 0, 1); // disable CS

    chThdSleepMilliseconds(1);
  }
  chThdExit((msg_t)0);
}
static msg_t ThreadX(void *arg) { ((attr_parent *)arg)->ThreadX2(); }
WORKING_AREA(waThreadX, 1024);
Thread *Thd;

Privacy

© 2024 Zrna Research