Exemple #1
0
static PyObject *SPIDev_setLSBFirst(SPIDev *self, PyObject *args, 
                                    PyObject *kwds) {
  uint8_t cs;
  if (self->spidev_fd[0] < 0) {
    PyErr_SetString(PyExc_IOError, 
      "must call SPIDev.open() first to initialize the SPI interface");
    return NULL;
  }
  if(!PyArg_ParseTuple(args, "b", &cs)) {
    return NULL;
  }
  if (SPIDev_activateCS(self, cs) < 0) return NULL;

  if (SPI_setBitOrder(self->spidev_fd[cs], SPI_LSBFIRST) < 0) {
    PyErr_SetString(PyExc_IOError, "could not set SPI bit order");
    return NULL;
  }
  Py_INCREF(Py_None);
  return Py_None;
}
void ST7735_init(u8 module, u8 cs, u8 dc, u8 sda, u8 sck)
{
    ST7735_SPI = module;
    
    ST7735[module].pin.dc = dc;
    ST7735[module].pin.cs = cs;
    output(ST7735[module].pin.dc);
    output(ST7735[module].pin.cs);
    
    // init SPI communication

    if (module == SPISW)
    {
        SPI_setPin(ST7735_SPI, sda, sck);
        SPI_setBitOrder(ST7735_SPI, SPI_MSBFIRST);
    }
    else
    {
        SPI_setMode(ST7735_SPI, SPI_MASTER8);
        SPI_setDataMode(ST7735_SPI, SPI_MODE1);
        //maximum baud rate possible = FPB/2
        SPI_setClockDivider(ST7735_SPI, SPI_PBCLOCK_DIV2);
        SPI_begin(ST7735_SPI);
    }
    
    // default Screen Values

    ST7735[module].cursor.x      = 0;
    ST7735[module].cursor.y      = 0;
    ST7735[module].cursor.page   = 0;
    ST7735[module].screen.startx = 0;
    ST7735[module].screen.starty = 0;
    ST7735[module].screen.endx   = ST7735_WIDTH  - 1;
    ST7735[module].screen.endy   = ST7735_HEIGHT - 1;
    ST7735[module].screen.width  = ST7735_WIDTH;
    ST7735[module].screen.height = ST7735_HEIGHT;
    //ST7735[module].font.width    = 1;
    //ST7735[module].font.height   = 1;

    // Software reset and minimal init.
    
    ST7735_low(ST7735[module].pin.cs);             // Chip select
    
    ST7735_sendCommand(module,(u8)ST7735_SWRESET); // software reset, puts display into sleep
    Delayms(150);
    ST7735_sendCommand(module,(u8)ST7735_SLPOUT);  // wake from sleep
    Delayms(500);
    ST7735_sendCommand(module,(u8)ST7735_COLMOD);  // set color mode to 16-bit
    ST7735_sendData(module,0x05);
    Delayms(10);
    ST7735_sendCommand(module,(u8)ST7735_MADCTL);  // RGB
    ST7735_sendData(module, 0x60|ST7735_MADCTL_RGB);
    Delayms(10);
    ST7735_sendCommand(module,(u8)ST7735_DISPON);  // display on!
    Delayms(100);
    ST7735_sendCommand(module,(u8)ST7735_NORON);   // normal display
    Delayms(10);
    
    ST7735_high(ST7735[module].pin.cs);            // Chip deselected
    
    // Default colors and orientation
    
    //ST7735_setOrientation(module, 90);             // landscape orientation
    ST7735_setBackgroundColor(module, ST7735_BLACK);
    ST7735_setColor(module, ST7735_WHITE);
    ST7735_clearScreen(module);
}