Changeset 6000:e96f8ed8280b in roaraudio


Ignore:
Timestamp:
02/25/14 16:34:47 (5 years ago)
Author:
phi
Branch:
default
Message:

hard disable SPI mode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roard/driver_i2cdmx.c

    r5999 r6000  
    3131#include <linux/i2c-dev.h> 
    3232 
     33// hard disable SPI mode. 
     34#ifdef ROAR_HAVE_H_LINUX_SPI_SPIDEV 
     35#undef ROAR_HAVE_H_LINUX_SPI_SPIDEV 
     36#endif 
     37 
    3338#ifdef ROAR_HAVE_H_LINUX_SPI_SPIDEV 
    3439#include <linux/spi/spidev.h> 
    3540#include <sys/ioctl.h> 
    3641 
    37 #define TRANSFER_DELAY 5 
    38 #define TRANSFER_SPEED 1000000 
     42#define TRANSFER_DELAY 50 
     43#define TRANSFER_SPEED 100000 
    3944#define TRANSFER_BPW   8 
     45#define TRANSFER_CHANS 24 
     46#define TRANSFER_SIZE  (TRANSFER_CHANS+6) 
     47#define SPI_DEVICE     "file://dev/spidev0.0" 
    4048#endif 
    4149 
     
    7583 size_t startaddr; 
    7684 size_t len; 
     85#ifdef ROAR_HAVE_H_LINUX_SPI_SPIDEV 
     86 char txtransfer[TRANSFER_SIZE]; 
     87 char rxtransfer[TRANSFER_SIZE]; 
     88#endif 
    7789}; 
    7890 
    79 static int __spi_transfer(struct driver_i2cdmx * self, void * txbuffer, void * rxbuffer, size_t len) { 
    80 #ifdef ROAR_HAVE_H_LINUX_SPI_SPIDEV 
     91#ifdef ROAR_HAVE_H_LINUX_SPI_SPIDEV 
     92static int __spi_transfer(struct driver_i2cdmx * self, size_t offset_in, size_t offset_out, size_t len) { 
    8193 struct spi_ioc_transfer transfer_buffer = { 
    82   .tx_buf = (unsigned long) txbuffer, 
    83   .rx_buf = (unsigned long) rxbuffer, 
     94  .tx_buf = (unsigned long) self->txtransfer, 
     95  .rx_buf = (unsigned long) self->rxtransfer, 
    8496  .len = len, 
    8597  .delay_usecs = TRANSFER_DELAY, 
     
    89101 struct roar_vio_sysio_ioctl ctl = {.cmd = SPI_IOC_MESSAGE(1), .argp = &transfer_buffer}; 
    90102 
     103 self->txtransfer[0] = 1; // command 
     104 self->txtransfer[1] = len; 
     105 self->txtransfer[2] = (offset_in & 0xFF00) >> 8; 
     106 self->txtransfer[3] =  offset_in & 0x00FF; 
     107 self->txtransfer[4] = (offset_in & 0xFF00) >> 8; 
     108 self->txtransfer[5] =  offset_in & 0x00FF; 
     109 
    91110 if ( roar_vio_ctl(&(self->spi), ROAR_VIO_CTL_SYSIO_IOCTL, &ctl) == -1 ) 
    92111  return -1; 
    93112 
    94113 return 0; 
    95 #else 
    96  roar_err_set(ROAR_ERROR_NOSYS); 
    97  return -1; 
    98 #endif 
    99 } 
     114} 
     115#endif 
    100116 
    101117static inline int __i2c_set_slave(struct driver_i2cdmx * self) { 
     
    312328 self = vio->inst; 
    313329 
     330 if ( count != 512 ) { 
     331  roar_err_set(ROAR_ERROR_INVAL); 
     332  return -1; 
     333 } 
     334 
    314335 if ( __i2c_start_dmx(self) == -1 ) 
    315336  return -1; 
    316337 
    317  roar_err_set(ROAR_ERROR_NOSYS); 
    318  return -1; 
     338 memset(buf, 0, count); // optimize this... 
     339#ifdef ROAR_HAVE_H_LINUX_SPI_SPIDEV 
     340 memcpy(buf, self->rxtransfer+6, sizeof(self->rxtransfer)-6); 
     341#endif 
     342 return 0; 
    319343} 
    320344 
     
    342366  if ( __i2c_write_channel(self, i, ((uint8_t*)buf)[i]) == -1 ) 
    343367   return -1; 
     368#ifdef ROAR_HAVE_H_LINUX_SPI_SPIDEV 
     369 memcpy(self->txtransfer+6, buf, sizeof(self->txtransfer)-6); 
     370 __spi_transfer(self, 0, 0, TRANSFER_CHANS); 
     371#endif 
    344372 
    345373 return count; 
     
    417445 } 
    418446 
     447#if defined(ROAR_HAVE_H_LINUX_SPI_SPIDEV) && defined(SPI_DEVICE) 
     448 if ( roar_vio_open_dstr_simple(&(self->spi), SPI_DEVICE, ROAR_VIOF_READWRITE) == 0 ) 
     449  self->have_spi = 1; 
     450#endif 
     451 
    419452 roar_vio_clear_calls(inst); 
    420453 inst->inst  = self; 
Note: See TracChangeset for help on using the changeset viewer.