Class: Pigpio::BscXfer
- Inherits:
-
Object
- Object
- Pigpio::BscXfer
- Defined in:
- ext/pigpio/pigpio.c
Class Method Summary collapse
-
.make ⇒ Object
Constructor of bsc_xfer_t as Pigpio::BscXfer class.
Instance Method Summary collapse
-
#close ⇒ Object
Close slave I/F.
-
#control ⇒ Object
Get control.
-
#control=(control) ⇒ Object
Setter.
-
#rxBuf ⇒ Object
Get RX buffer.
-
#stop ⇒ Object
Stop trans.
-
#txBuf=(txBuf) ⇒ Object
Set TX buffer.
Class Method Details
.make ⇒ Object
Constructor of bsc_xfer_t as Pigpio::BscXfer class
typedef struct
{
uint32_t control; // Write
int rxCnt; // Read only
char rxBuf[BSC_FIFO_SIZE]; // Read only
int txCnt; // Write
char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;
212 213 214 215 216 217 218 219 220 |
# File 'ext/pigpio/pigpio.c', line 212
VALUE pigpio_rbst_bsc_xfer_make(VALUE self){
VALUE obj;
bsc_xfer_t *st;
obj = TypedData_Make_Struct(self, bsc_xfer_t, &bsc_xfer_data_type, st);
st->control=0;
st->txCnt=0;
st->rxCnt=0;
return obj;
}
|
Instance Method Details
#close ⇒ Object
Close slave I/F
275 276 277 278 279 |
# File 'ext/pigpio/pigpio.c', line 275
VALUE pigpio_rbst_bsc_xfer_close(VALUE self){
bsc_xfer_t *st=TypedData_Get_Struct2(self,bsc_xfer_t,&bsc_xfer_data_type);
st->control=st->control&0xfffffffcL;
return ULONG2NUM(st->control);
}
|
#control ⇒ Object
Get control
260 261 262 263 |
# File 'ext/pigpio/pigpio.c', line 260
VALUE pigpio_rbst_bsc_xfer_r_control(VALUE self){
bsc_xfer_t *st=TypedData_Get_Struct2(self,bsc_xfer_t,&bsc_xfer_data_type);
return ULONG2NUM(st->control);
}
|
#control=(control) ⇒ Object
Setter
224 225 226 227 228 |
# File 'ext/pigpio/pigpio.c', line 224
VALUE pigpio_rbst_bsc_xfer_w_control(VALUE self,VALUE control){
bsc_xfer_t *st=TypedData_Get_Struct2(self,bsc_xfer_t,&bsc_xfer_data_type);
st->control=NUM2ULONG(control);
return self;
}
|
#rxBuf ⇒ Object
Get RX buffer
245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'ext/pigpio/pigpio.c', line 245
VALUE pigpio_rbst_bsc_xfer_r_rxBuf(VALUE self){
bsc_xfer_t *st=TypedData_Get_Struct2(self,bsc_xfer_t,&bsc_xfer_data_type);
return rb_str_new(st->rxBuf,st->rxCnt);
/*
VALUE rxBuf=rb_str_new("",st->rxCnt);
char *buf=StringValuePtr(rxBuf);
for(int i=0;i<st->rxCnt;i++){
*buf++=st->rxBuf[i];
}
return rxBuf;
*/
}
|
#stop ⇒ Object
Stop trans
267 268 269 270 271 |
# File 'ext/pigpio/pigpio.c', line 267
VALUE pigpio_rbst_bsc_xfer_stop(VALUE self){
bsc_xfer_t *st=TypedData_Get_Struct2(self,bsc_xfer_t,&bsc_xfer_data_type);
st->control=st->control|0x00000080L;
return ULONG2NUM(st->control);
}
|
#txBuf=(txBuf) ⇒ Object
Set TX buffer
232 233 234 235 236 237 238 239 240 241 |
# File 'ext/pigpio/pigpio.c', line 232
VALUE pigpio_rbst_bsc_xfer_w_txBuf(VALUE self,VALUE txBuf){
bsc_xfer_t *st=TypedData_Get_Struct2(self,bsc_xfer_t,&bsc_xfer_data_type);
int len=RSTRING_LEN(txBuf);
char *buf=StringValuePtr(txBuf);
st->txCnt=(len<BSC_FIFO_SIZE)?len:BSC_FIFO_SIZE;
memcpy(st->txBuf,buf,st->txCnt);
//for(int i=0;i<st->txCnt;i++){st->txBuf[i]=*buf++;}
RB_GC_GUARD(txBuf);
return self;
}
|