Lines Matching refs:mpsse
60 struct mpsse_context* mpsse = NULL; in MPSSE() local
63 mpsse = Open(supported_devices[i].vid, supported_devices[i].pid, mode, in MPSSE()
65 if (mpsse) { in MPSSE()
66 mpsse->description = supported_devices[i].description; in MPSSE()
67 return mpsse; in MPSSE()
127 struct mpsse_context* mpsse = NULL; in OpenIndex() local
129 mpsse = malloc(sizeof(struct mpsse_context)); in OpenIndex()
130 if (!mpsse) in OpenIndex()
133 memset(mpsse, 0, sizeof(struct mpsse_context)); in OpenIndex()
136 FlushAfterRead(mpsse, 0); in OpenIndex()
139 if (ftdi_init(&mpsse->ftdi)) { in OpenIndex()
140 free(mpsse); in OpenIndex()
145 ftdi_set_interface(&mpsse->ftdi, interface); in OpenIndex()
148 if (!ftdi_usb_open_desc_index(&mpsse->ftdi, vid, pid, description, serial, in OpenIndex()
150 mpsse->mode = mode; in OpenIndex()
151 mpsse->vid = vid; in OpenIndex()
152 mpsse->pid = pid; in OpenIndex()
153 mpsse->status = STOPPED; in OpenIndex()
154 mpsse->endianess = endianess; in OpenIndex()
157 if (mpsse->mode == I2C) in OpenIndex()
158 mpsse->xsize = I2C_TRANSFER_SIZE; in OpenIndex()
160 mpsse->xsize = SPI_RW_SIZE; in OpenIndex()
162 status |= ftdi_usb_reset(&mpsse->ftdi); in OpenIndex()
163 status |= ftdi_set_latency_timer(&mpsse->ftdi, LATENCY_MS); in OpenIndex()
164 status |= ftdi_write_data_set_chunksize(&mpsse->ftdi, CHUNK_SIZE); in OpenIndex()
165 status |= ftdi_read_data_set_chunksize(&mpsse->ftdi, CHUNK_SIZE); in OpenIndex()
166 status |= ftdi_set_bitmode(&mpsse->ftdi, 0, BITMODE_RESET); in OpenIndex()
170 set_timeouts(mpsse, USB_TIMEOUT); in OpenIndex()
172 if (mpsse->mode != BITBANG) { in OpenIndex()
173 ftdi_set_bitmode(&mpsse->ftdi, 0, BITMODE_MPSSE); in OpenIndex()
175 if (SetClock(mpsse, freq) == MPSSE_OK) { in OpenIndex()
176 if (SetMode(mpsse, endianess) == MPSSE_OK) { in OpenIndex()
177 mpsse->opened = 1; in OpenIndex()
188 ftdi_usb_purge_buffers(&mpsse->ftdi); in OpenIndex()
194 if (!ftdi_set_bitmode(&mpsse->ftdi, 0xFF, BITMODE_BITBANG)) in OpenIndex()
195 mpsse->opened = 1; in OpenIndex()
200 if (mpsse && !mpsse->opened) { in OpenIndex()
201 Close(mpsse); in OpenIndex()
202 mpsse = NULL; in OpenIndex()
205 return mpsse; in OpenIndex()
216 void Close(struct mpsse_context* mpsse) { in Close() argument
217 if (!mpsse) in Close()
220 if (mpsse->opened) { in Close()
222 ftdi_set_bitmode(&mpsse->ftdi, 0, BITMODE_RESET); in Close()
223 ftdi_usb_close(&mpsse->ftdi); in Close()
225 ftdi_deinit(&mpsse->ftdi); in Close()
226 free(mpsse); in Close()
234 void EnableBitmode(struct mpsse_context* mpsse, int tf) { in EnableBitmode() argument
235 if (is_valid_context(mpsse)) { in EnableBitmode()
237 mpsse->tx |= MPSSE_BITMODE; in EnableBitmode()
238 mpsse->rx |= MPSSE_BITMODE; in EnableBitmode()
239 mpsse->txrx |= MPSSE_BITMODE; in EnableBitmode()
241 mpsse->tx &= ~MPSSE_BITMODE; in EnableBitmode()
242 mpsse->rx &= ~MPSSE_BITMODE; in EnableBitmode()
243 mpsse->txrx &= ~MPSSE_BITMODE; in EnableBitmode()
258 int SetMode(struct mpsse_context* mpsse, int endianess) { in SetMode() argument
265 if (mpsse) { in SetMode()
267 mpsse->tx = MPSSE_DO_WRITE | endianess; in SetMode()
268 mpsse->rx = MPSSE_DO_READ | endianess; in SetMode()
269 mpsse->txrx = MPSSE_DO_WRITE | MPSSE_DO_READ | endianess; in SetMode()
272 mpsse->tris = DEFAULT_TRIS; in SetMode()
275 mpsse->pidle = mpsse->pstart = mpsse->pstop = DEFAULT_PORT; in SetMode()
278 mpsse->pstart &= ~CS; in SetMode()
281 SetLoopback(mpsse, 0); in SetMode()
284 SetAck(mpsse, ACK); in SetMode()
289 switch (mpsse->mode) { in SetMode()
292 mpsse->pidle &= ~SK; in SetMode()
293 mpsse->pstart &= ~SK; in SetMode()
294 mpsse->pstop &= ~SK; in SetMode()
297 mpsse->tx |= MPSSE_WRITE_NEG; in SetMode()
298 mpsse->rx &= ~MPSSE_READ_NEG; in SetMode()
299 mpsse->txrx |= MPSSE_WRITE_NEG; in SetMode()
300 mpsse->txrx &= ~MPSSE_READ_NEG; in SetMode()
304 mpsse->pidle |= SK; in SetMode()
305 mpsse->pstart |= SK; in SetMode()
308 mpsse->pstop &= ~SK; in SetMode()
311 mpsse->tx |= MPSSE_WRITE_NEG; in SetMode()
312 mpsse->rx &= ~MPSSE_READ_NEG; in SetMode()
313 mpsse->txrx |= MPSSE_WRITE_NEG; in SetMode()
314 mpsse->txrx &= ~MPSSE_READ_NEG; in SetMode()
318 mpsse->pidle &= ~SK; in SetMode()
321 mpsse->pstart &= ~SK; in SetMode()
328 mpsse->pstop |= SK; in SetMode()
330 mpsse->rx |= MPSSE_READ_NEG; in SetMode()
331 mpsse->tx &= ~MPSSE_WRITE_NEG; in SetMode()
332 mpsse->txrx |= MPSSE_READ_NEG; in SetMode()
333 mpsse->txrx &= ~MPSSE_WRITE_NEG; in SetMode()
337 mpsse->pidle |= SK; in SetMode()
338 mpsse->pstart |= SK; in SetMode()
339 mpsse->pstop |= SK; in SetMode()
341 mpsse->rx |= MPSSE_READ_NEG; in SetMode()
342 mpsse->tx &= ~MPSSE_WRITE_NEG; in SetMode()
343 mpsse->txrx |= MPSSE_READ_NEG; in SetMode()
344 mpsse->txrx &= ~MPSSE_WRITE_NEG; in SetMode()
349 mpsse->tx |= MPSSE_WRITE_NEG; in SetMode()
350 mpsse->rx &= ~MPSSE_READ_NEG; in SetMode()
352 mpsse->pidle |= DO | DI; in SetMode()
355 mpsse->pstart &= ~DO & ~DI; in SetMode()
359 mpsse->pstop &= ~DO & ~DI; in SetMode()
372 retval = raw_write(mpsse, setup_commands, setup_commands_size); in SetMode()
377 set_bits_low(mpsse, mpsse->pidle); in SetMode()
380 mpsse->trish = 0xFF; in SetMode()
381 mpsse->gpioh = 0x00; in SetMode()
384 buf[i++] = mpsse->gpioh; in SetMode()
385 buf[i++] = mpsse->trish; in SetMode()
387 retval = raw_write(mpsse, buf, i); in SetMode()
405 int SetClock(struct mpsse_context* mpsse, uint32_t freq) { in SetClock() argument
413 if (mpsse) { in SetClock()
422 if (raw_write(mpsse, buf, 1) == MPSSE_OK) { in SetClock()
433 if (raw_write(mpsse, buf, 3) == MPSSE_OK) { in SetClock()
434 mpsse->clock = div2freq(system_clock, divisor); in SetClock()
450 const char* ErrorString(struct mpsse_context* mpsse) { in ErrorString() argument
451 if (mpsse != NULL) { in ErrorString()
452 return ftdi_get_error_string(&mpsse->ftdi); in ErrorString()
465 int GetClock(struct mpsse_context* mpsse) { in GetClock() argument
468 if (is_valid_context(mpsse)) { in GetClock()
469 clock = mpsse->clock; in GetClock()
482 int GetVid(struct mpsse_context* mpsse) { in GetVid() argument
485 if (is_valid_context(mpsse)) { in GetVid()
486 vid = mpsse->vid; in GetVid()
499 int GetPid(struct mpsse_context* mpsse) { in GetPid() argument
502 if (is_valid_context(mpsse)) { in GetPid()
503 pid = mpsse->pid; in GetPid()
516 const char* GetDescription(struct mpsse_context* mpsse) { in GetDescription() argument
519 if (is_valid_context(mpsse)) { in GetDescription()
520 description = mpsse->description; in GetDescription()
535 int SetLoopback(struct mpsse_context* mpsse, int enable) { in SetLoopback() argument
539 if (is_valid_context(mpsse)) { in SetLoopback()
546 retval = raw_write(mpsse, buf, 1); in SetLoopback()
560 void SetCSIdle(struct mpsse_context* mpsse, int idle) { in SetCSIdle() argument
561 if (is_valid_context(mpsse)) { in SetCSIdle()
564 mpsse->pidle |= CS; in SetCSIdle()
565 mpsse->pstop |= CS; in SetCSIdle()
566 mpsse->pstart &= ~CS; in SetCSIdle()
569 mpsse->pidle &= ~CS; in SetCSIdle()
570 mpsse->pstop &= ~CS; in SetCSIdle()
571 mpsse->pstart |= CS; in SetCSIdle()
588 void FlushAfterRead(struct mpsse_context* mpsse, int tf) { in FlushAfterRead() argument
589 mpsse->flush_after_read = tf; in FlushAfterRead()
601 int Start(struct mpsse_context* mpsse) { in Start() argument
604 if (is_valid_context(mpsse)) { in Start()
605 if (mpsse->mode == I2C && mpsse->status == STARTED) { in Start()
608 status |= set_bits_low(mpsse, (mpsse->pidle & ~SK)); in Start()
611 status |= set_bits_low(mpsse, mpsse->pidle); in Start()
615 status |= set_bits_low(mpsse, mpsse->pstart); in Start()
622 if (mpsse->mode == SPI3) { in Start()
623 status |= set_bits_low(mpsse, (mpsse->pstart & ~SK)); in Start()
630 else if (mpsse->mode == SPI1) { in Start()
631 status |= set_bits_low(mpsse, (mpsse->pstart | SK)); in Start()
634 mpsse->status = STARTED; in Start()
637 mpsse->status = STOPPED; in Start()
652 int WriteBits(struct mpsse_context* mpsse, char bits, size_t size) { in WriteBits() argument
665 if (mpsse->endianess == LSB) { in WriteBits()
674 EnableBitmode(mpsse, 1); in WriteBits()
675 retval = Write(mpsse, data, size); in WriteBits()
676 EnableBitmode(mpsse, 0); in WriteBits()
691 int Write(struct mpsse_context* mpsse, const void* vdata, int size) { in Write() argument
696 if (is_valid_context(mpsse)) { in Write()
697 if (mpsse->mode) { in Write()
700 if (txsize > mpsse->xsize) { in Write()
701 txsize = mpsse->xsize; in Write()
708 if (mpsse->mode == I2C) { in Write()
712 buf = build_block_buffer(mpsse, mpsse->tx, data + n, txsize, &buf_size); in Write()
714 retval = raw_write(mpsse, buf, buf_size); in Write()
723 if (mpsse->mode == I2C) { in Write()
724 raw_read(mpsse, (uint8_t*)&mpsse->rack, 1); in Write()
741 static uint8_t* InternalRead(struct mpsse_context* mpsse, int size) { in InternalRead() argument
746 if (is_valid_context(mpsse)) { in InternalRead()
747 if (mpsse->mode) { in InternalRead()
754 if (rxsize > mpsse->xsize) { in InternalRead()
755 rxsize = mpsse->xsize; in InternalRead()
758 data = build_block_buffer(mpsse, mpsse->rx, sbuf, rxsize, &data_size); in InternalRead()
760 retval = raw_write(mpsse, data, data_size); in InternalRead()
764 n += raw_read(mpsse, buf + n, rxsize); in InternalRead()
789 swig_string_data Read(struct mpsse_context* mpsse, int size) in Read() argument
791 uint8_t* Read(struct mpsse_context* mpsse, int size) in Read()
796 buf = InternalRead(mpsse, size); in Read()
816 char ReadBits(struct mpsse_context* mpsse, int size) { in ReadBits() argument
824 EnableBitmode(mpsse, 1); in ReadBits()
825 rdata = InternalRead(mpsse, size); in ReadBits()
826 EnableBitmode(mpsse, 0); in ReadBits()
833 if (mpsse->endianess == MSB) { in ReadBits()
839 } else if (mpsse->endianess == LSB) { in ReadBits()
865 swig_string_data Transfer(struct mpsse_context* mpsse, char* data, int size) in Transfer() argument
867 uint8_t* Transfer(struct mpsse_context* mpsse, uint8_t* data, int size) in Transfer()
873 if (is_valid_context(mpsse)) { in Transfer()
875 if (mpsse->mode >= SPI0 && mpsse->mode <= SPI3) { in Transfer()
889 build_block_buffer(mpsse, mpsse->txrx, data + n, in Transfer()
892 retval = raw_write(mpsse, txdata, data_size); in Transfer()
896 n += raw_read(mpsse, (buf + n), rxsize); in Transfer()
925 int GetAck(struct mpsse_context* mpsse) { in GetAck() argument
928 if (is_valid_context(mpsse)) { in GetAck()
929 ack = (mpsse->rack & 0x01); in GetAck()
943 void SetAck(struct mpsse_context* mpsse, int ack) { in SetAck() argument
944 if (is_valid_context(mpsse)) { in SetAck()
946 mpsse->tack = 0xFF; in SetAck()
948 mpsse->tack = 0x00; in SetAck()
962 void SendAcks(struct mpsse_context* mpsse) { in SendAcks() argument
963 return SetAck(mpsse, ACK); in SendAcks()
973 void SendNacks(struct mpsse_context* mpsse) { in SendNacks() argument
974 return SetAck(mpsse, NACK); in SendNacks()
985 int Stop(struct mpsse_context* mpsse) { in Stop() argument
988 if (is_valid_context(mpsse)) { in Stop()
991 if (mpsse->mode == I2C) { in Stop()
992 retval |= set_bits_low(mpsse, (mpsse->pidle & ~DO & ~SK)); in Stop()
996 retval |= set_bits_low(mpsse, mpsse->pstop); in Stop()
1000 retval |= set_bits_low(mpsse, mpsse->pidle); in Stop()
1003 mpsse->status = STOPPED; in Stop()
1006 mpsse->status = STOPPED; in Stop()
1021 int PinHigh(struct mpsse_context* mpsse, int pin) { in PinHigh() argument
1024 if (is_valid_context(mpsse)) { in PinHigh()
1025 retval = gpio_write(mpsse, pin, HIGH); in PinHigh()
1040 int PinLow(struct mpsse_context* mpsse, int pin) { in PinLow() argument
1043 if (is_valid_context(mpsse)) { in PinLow()
1044 retval = gpio_write(mpsse, pin, LOW); in PinLow()
1058 int SetDirection(struct mpsse_context* mpsse, uint8_t direction) { in SetDirection() argument
1061 if (is_valid_context(mpsse)) { in SetDirection()
1062 if (mpsse->mode == BITBANG) { in SetDirection()
1063 if (ftdi_set_bitmode(&mpsse->ftdi, direction, BITMODE_BITBANG) == 0) { in SetDirection()
1080 int WritePins(struct mpsse_context* mpsse, uint8_t data) { in WritePins() argument
1083 if (is_valid_context(mpsse)) { in WritePins()
1084 if (mpsse->mode == BITBANG) { in WritePins()
1085 if (ftdi_write_data(&mpsse->ftdi, &data, 1) == 0) { in WritePins()
1101 int ReadPins(struct mpsse_context* mpsse) { in ReadPins() argument
1104 if (is_valid_context(mpsse)) { in ReadPins()
1105 ftdi_read_pins((struct ftdi_context*)&mpsse->ftdi, (uint8_t*)&val); in ReadPins()
1121 int PinState(struct mpsse_context* mpsse, int pin, int state) { in PinState() argument
1123 state = ReadPins(mpsse); in PinState()
1128 if (mpsse->mode != BITBANG) { in PinState()
1142 int Tristate(struct mpsse_context* mpsse) { in Tristate() argument
1150 return raw_write(mpsse, cmd, sizeof(cmd)); in Tristate()