Skip to content
Snippets Groups Projects
Select Git revision
  • a13422fe2b044b26b667f4e045ce8cfedd6ec647
  • master default protected
  • dither_on_off_disabled
  • yocto
  • pypcc2
  • pypcc3
  • 2020-12-07-the_only_working_copy
  • v2.1
  • v2.0
  • v1.0
  • v0.9
  • Working-RCU_ADC,ID
  • 2020-12-11-Holiday_Season_release
13 results

spibitbang1.cpp

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    spibitbang1.cpp 1.90 KiB
    #include "spibitbang1.h"
    #include "../apsctl/conf.h"
    #include <iostream>
    
    
    c_spibitbang1::c_spibitbang1(const t_driver config1) : drvbase (config1){
      CLK=config1.devreg[0];
      SDIO=config1.devreg[1];
      SDIOdir=config1.devreg[2];
      CS=config1.devreg[3];
      CLKpin=config1.parameters[0];
      SDIOpin=config1.parameters[1];
      CSpin=config1.parameters[2];
    };
    
    bool c_spibitbang1::I2Csend(int addr,int reg,int len,t_buffer* data,int direction){
      t_buffer bit[1]={0};
      if (direction==0) {  //Send
        int data2 = ( 0x00 << 23 ) + ( 0x00 << 21 ) + ( reg << 8 ) + data[0];
        std::cout << "SPI send" << data2 << "\n";          
        bit[0]={0};parent->seti2c(CS,1,CSpin,bit);
        for (int x=0;x<32;x++)
        {
          bit[0]=(data2>>(31-x)) & 1;  //Not that efficient, but works
          parent->seti2c(SDIO,1,SDIOpin,bit);
          bit[0]={1};parent->seti2c(CLK,1,CLKpin,bit);
          bit[0]={0};parent->seti2c(CLK,1,CLKpin,bit);
        }
        bit[0]={1};parent->seti2c(CS,1,CSpin,bit);
        bit[0]={1};parent->seti2c(SDIO,1,SDIOpin,bit);
      } else {
        int data2 = ( 0x01 << 15) + ( 0x00 << 13 ) + reg;
        bit[0]={0};parent->seti2c(CLK,1,CLKpin,bit);
        bit[0]={0};parent->seti2c(CS,1,CSpin,bit);//enable
        for (int x=0;x<16;x++){
          bit[0]={0};parent->seti2c(CLK,1,CLKpin,bit);
          bit[0]=(data2>>(15-x)) & 1;  //Not that efficient, but works
          parent->seti2c(SDIO,1,SDIOpin,bit);
          bit[0]={1};parent->seti2c(CLK,1,CLKpin,bit);
        }
        bit[0]=1;parent->seti2c(SDIOdir,1,SDIOpin,bit);
        bit[0]=0;parent->seti2c(CLK,1,CLKpin,bit);
    
        data2=0;
        for (int x=0;x<8;x++){
            parent->geti2c(SDIO,1,SDIOpin,bit);
            data2<<=2;
            data2+=bit[0];
            bit[0]=1;parent->seti2c(CLK,1,CLKpin,bit);
            bit[0]=0;parent->seti2c(CLK,1,CLKpin,bit);
          }
    
        bit[0]=1;parent->seti2c(CS,1,CSpin,bit);//disable
        bit[0]=1;parent->seti2c(SDIO,1,SDIOpin,bit);
        bit[0]=0;parent->seti2c(SDIOdir,1,SDIOpin,bit);
    
      }
      return true;
    }