Changeset 5904:768618299b76 in roaraudio


Ignore:
Timestamp:
04/21/13 02:02:41 (6 years ago)
Author:
phi
Branch:
default
Message:

added write support to special bar port

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/universal/piface.c

    r5903 r5904  
    170170} 
    171171 
     172static inline unsigned char __render_bar(int bits) { 
     173 unsigned char ret = 0; 
     174 int i; 
     175 
     176 // this is a generic version. As long as this is not called too often it should work fine. 
     177 
     178 for (i = 0; i < bits; i++) { 
     179  ret <<= 1; 
     180  ret  |= 1; 
     181 } 
     182 
     183 return ret; 
     184} 
     185 
    172186 // get list of gpio IDs. 
    173187 // buffer is passed as ids, buffer size (in elements) is passed as len. 
     
    308322 port = &(state->ports[id]); 
    309323 
    310  if ( !(port->mode & ROAR_SERVICE_GPIO_FOUTPUT) || port->type != ROAR_SERVICE_GPIO_TBOOL ) { 
     324 if ( !(port->mode & ROAR_SERVICE_GPIO_FOUTPUT) ) { 
    311325  roar_err_set(ROAR_ERROR_NOTSUP); 
    312326  return -1; 
    313327 } 
    314328 
    315  bit = 1 << (id & 0x07); 
    316  
    317  buffer = state->buffer_output; 
    318  buffer |= bit; 
    319  
    320  if ( !val ) 
    321   buffer -= bit; 
    322  
    323  piface__write_output(buffer); 
    324  
    325  return 0; 
     329 if ( val < port->irange_min || val > port->irange_max ) { 
     330  roar_err_set(ROAR_ERROR_RANGE); 
     331  return -1; 
     332 } 
     333 
     334 switch (port->type) { 
     335  case ROAR_SERVICE_GPIO_TBOOL: 
     336    bit = 1 << (id & 0x07); 
     337 
     338    buffer = state->buffer_output; 
     339    buffer |= bit; 
     340 
     341    if ( !val ) 
     342     buffer -= bit; 
     343 
     344    piface__write_output(buffer); 
     345 
     346    return 0; 
     347   break; 
     348  case ROAR_SERVICE_GPIO_TINT: 
     349    piface__write_output(__render_bar(val)); 
     350    return 0; 
     351   break; 
     352  default: 
     353    roar_err_set(ROAR_ERROR_NOTSUP); 
     354    return -1; 
     355   break; 
     356 } 
    326357} 
    327358 
Note: See TracChangeset for help on using the changeset viewer.