Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multi-session GPIO #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions src/mpsse.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,9 @@ static struct mpsse_context *OpenIndexInternal(int vid, int pid, enum modes mode
mpsse->xsize = SPI_RW_SIZE;
}

status |= ftdi_usb_reset(&mpsse->ftdi);
status |= ftdi_set_latency_timer(&mpsse->ftdi, LATENCY_MS);
status |= ftdi_write_data_set_chunksize(&mpsse->ftdi, CHUNK_SIZE);
status |= ftdi_read_data_set_chunksize(&mpsse->ftdi, CHUNK_SIZE);
status |= ftdi_set_bitmode(&mpsse->ftdi, 0, BITMODE_RESET);

if(status == 0)
{
Expand Down Expand Up @@ -239,7 +237,6 @@ void Close(struct mpsse_context *mpsse)
{
if(mpsse->open)
{
ftdi_set_bitmode(&mpsse->ftdi, 0, BITMODE_RESET);
ftdi_usb_close(&mpsse->ftdi);
ftdi_deinit(&mpsse->ftdi);
}
Expand Down Expand Up @@ -286,8 +283,7 @@ void EnableBitmode(struct mpsse_context *mpsse, int tf)
*/
int SetMode(struct mpsse_context *mpsse, int endianess)
{
int retval = MPSSE_OK, i = 0, setup_commands_size = 0;
unsigned char buf[CMD_SIZE] = { 0 };
int retval = MPSSE_OK, setup_commands_size = 0;
unsigned char setup_commands[CMD_SIZE*MAX_SETUP_COMMANDS] = { 0 };

/* Do not call is_valid_context() here, as the FTDI chip may not be completely configured when SetMode is called */
Expand Down Expand Up @@ -395,18 +391,16 @@ int SetMode(struct mpsse_context *mpsse, int endianess)

if(retval == MPSSE_OK)
{
/* Set the idle pin states */
set_bits_low(mpsse, mpsse->pidle);

/* All GPIO pins are outputs, set low */
mpsse->trish = 0xFF;
mpsse->gpioh = 0x00;
uint8_t low_pins, high_pins;
if (get_bits_low(mpsse, &low_pins) != MPSSE_OK) low_pins = 0;
if (get_bits_high(mpsse, &high_pins) != MPSSE_OK) high_pins = 0;

buf[i++] = SET_BITS_HIGH;
buf[i++] = mpsse->gpioh;
buf[i++] = mpsse->trish;
mpsse->pstart = low_pins;
mpsse->gpioh = high_pins;

retval = raw_write(mpsse, buf, i);
/* All GPIO pins are outputs */
mpsse->tris |= GPIO0 | GPIO1 | GPIO2 | GPIO3;
mpsse->trish = 0xFF;
}
}
else
Expand Down
10 changes: 10 additions & 0 deletions src/support.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ int set_bits_high(struct mpsse_context *mpsse, int port)
return raw_write(mpsse, (unsigned char *) &buf, sizeof(buf));
}

int get_bits_low(struct mpsse_context *mpsse, uint8_t* value) {
unsigned char buf[] = { GET_BITS_LOW };

int res = raw_write(mpsse, buf, sizeof(buf));
if (res != MPSSE_OK) return res;

if (raw_read(mpsse, value, 1) != 1) return MPSSE_FAIL;
return MPSSE_OK;
}

int get_bits_high(struct mpsse_context *mpsse, uint8_t* value) {
unsigned char buf[] = { GET_BITS_HIGH };

Expand Down
1 change: 1 addition & 0 deletions src/support.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ unsigned char *build_block_buffer(struct mpsse_context *mpsse, uint8_t cmd, cons
int set_bits_high(struct mpsse_context *mpsse, int port);
int set_bits_low(struct mpsse_context *mpsse, int port);
int get_bits_high(struct mpsse_context *mpsse, uint8_t* value);
int get_bits_low(struct mpsse_context *mpsse, uint8_t* value);
int gpio_write(struct mpsse_context *mpsse, int pin, int direction);
int is_valid_context(struct mpsse_context *mpsse);

Expand Down