Skip to content

Commit

Permalink
Fix calling spifns_stream_sequence() from 1.3 API
Browse files Browse the repository at this point in the history
For #28
  • Loading branch information
lorf committed Mar 27, 2018
1 parent 20bfd00 commit 835dc2d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 53 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.3-a1
0.5.3-a2
103 changes: 53 additions & 50 deletions basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,35 +483,64 @@ static int spifns_sequence_read(unsigned short nAddress, unsigned short nLength,
return 1;
}

DLLEXPORT int spifns_sequence(SPISEQ *pSequence, unsigned int nCount) {
DLLEXPORT int spifns_sequence(void *pSequence, unsigned int nCount) {
int nRetval=0;
SPISEQ *pSequence13 = (SPISEQ *)pSequence;
SPISEQ_1_4 *pSequence14 = (SPISEQ_1_4 *)pSequence;

LOG(DEBUG, "(%p, %d)", pSequence, nCount);

while (nCount--) {
LOG(DEBUG, "command %d", pSequence->nType);
switch (pSequence->nType) {
case SPISEQ::TYPE_READ:{
if (spifns_sequence_read(pSequence->rw.nAddress,pSequence->rw.nLength,pSequence->rw.pnData)==1)
nRetval=1;
}break;
case SPISEQ::TYPE_WRITE:{
if (spifns_sequence_write(pSequence->rw.nAddress,pSequence->rw.nLength,pSequence->rw.pnData)==1)
nRetval=1;
if (spifns_api_version == SPIFNS_API_1_3) {
while (nCount--) {
LOG(DEBUG, "command %d", pSequence13->nType);
switch (pSequence13->nType) {
case SPISEQ::TYPE_READ:{
if (spifns_sequence_read(pSequence13->rw.nAddress,pSequence13->rw.nLength,pSequence13->rw.pnData)==1)
nRetval=1;
}break;
case SPISEQ::TYPE_SETVAR:{
if (spifns_sequence_setvar(pSequence->setvar.szName,pSequence->setvar.szValue)==1)
nRetval=1;
}break;
default:
LOG(WARN, "Sequence command not implemented: %d", pSequence->nType);
g_nError = SPIFNS_ERROR_INVALID_PARAMETER;
snprintf(g_szErrorString, sizeof(g_szErrorString),
"sequence command %d not implemented", pSequence->nType);
nRetval = 1;
case SPISEQ::TYPE_WRITE:{
if (spifns_sequence_write(pSequence13->rw.nAddress,pSequence13->rw.nLength,pSequence13->rw.pnData)==1)
nRetval=1;
}break;
case SPISEQ::TYPE_SETVAR:{
if (spifns_sequence_setvar(pSequence13->setvar.szName,pSequence13->setvar.szValue)==1)
nRetval=1;
}break;
default:
LOG(WARN, "Sequence command not implemented: %d", pSequence13->nType);
g_nError = SPIFNS_ERROR_INVALID_PARAMETER;
snprintf(g_szErrorString, sizeof(g_szErrorString),
"sequence command %d not implemented", pSequence13->nType);
nRetval = 1;

}
pSequence13++;
}
} else if (spifns_api_version == SPIFNS_API_1_4) {
while (nCount--) {
LOG(DEBUG, "command %d", pSequence14->nType);
switch (pSequence14->nType) {
case SPISEQ_1_4::TYPE_READ:
if (spifns_sequence_read(pSequence14->rw.nAddress,pSequence14->rw.nLength,pSequence14->rw.pnData)==1)
nRetval=1;
break;
case SPISEQ_1_4::TYPE_WRITE:
if (spifns_sequence_write(pSequence14->rw.nAddress,pSequence14->rw.nLength,pSequence14->rw.pnData)==1)
nRetval=1;
break;
case SPISEQ_1_4::TYPE_SETVAR:
if (spifns_sequence_setvar(pSequence14->setvar.szName,pSequence14->setvar.szValue)==1)
nRetval=1;
break;
default:
LOG(WARN, "Sequence command not implemented: %d", pSequence14->nType);
g_nError = SPIFNS_ERROR_INVALID_PARAMETER;
snprintf(g_szErrorString, sizeof(g_szErrorString),
"sequence command %d not implemented", pSequence14->nType);
nRetval = 1;
}
pSequence14++;
}
pSequence++;
}
return nRetval;
}
Expand Down Expand Up @@ -582,37 +611,11 @@ DLLEXPORT unsigned int spifns_count_streams(void)
return NSTREAMS;
}

DLLEXPORT int spifns_stream_sequence(spifns_stream_t stream, SPISEQ_1_4 *pSequence, int nCount)
DLLEXPORT int spifns_stream_sequence(spifns_stream_t stream, void *pSequence, int nCount)
{
int nRetval=0;

LOG(DEBUG, "(%d, %p, %d)", stream, pSequence, nCount);

while (nCount--) {
LOG(DEBUG, "command %d", pSequence->nType);
switch (pSequence->nType) {
case SPISEQ_1_4::TYPE_READ:
if (spifns_sequence_read(pSequence->rw.nAddress,pSequence->rw.nLength,pSequence->rw.pnData)==1)
nRetval=1;
break;
case SPISEQ_1_4::TYPE_WRITE:
if (spifns_sequence_write(pSequence->rw.nAddress,pSequence->rw.nLength,pSequence->rw.pnData)==1)
nRetval=1;
break;
case SPISEQ_1_4::TYPE_SETVAR:
if (spifns_sequence_setvar(pSequence->setvar.szName,pSequence->setvar.szValue)==1)
nRetval=1;
break;
default:
LOG(WARN, "Sequence command not implemented: %d", pSequence->nType);
g_nError = SPIFNS_ERROR_INVALID_PARAMETER;
snprintf(g_szErrorString, sizeof(g_szErrorString),
"sequence command %d not implemented", pSequence->nType);
nRetval = 1;
}
pSequence++;
}
return nRetval;
return spifns_sequence(pSequence, nCount);
}

DLLEXPORT const char* spifns_stream_command(spifns_stream_t stream, const char *command)
Expand Down
4 changes: 2 additions & 2 deletions spifns.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ DLLEXPORT const char* spifns_command(const char *szCmd); //Return 0 on no error,
/* get_last_error and clear_last_error both deal with the error that occurred in the current thread */
DLLEXPORT unsigned int spifns_get_last_error(unsigned short *pnErrorAddress, const char **szErrorString); //Returns where the error occured, or 0x100 for none
DLLEXPORT int spifns_bluecore_xap_stopped(); //Returns -1 on error, 0 on XAP running, 1 on stopped
DLLEXPORT int spifns_sequence(SPISEQ *pSequence, unsigned int nCount); //Return 0 on no error
DLLEXPORT int spifns_sequence(void *pSequence, unsigned int nCount); //Return 0 on no error
DLLEXPORT void spifns_set_debug_callback(spifns_debug_callback pCallback);
DLLEXPORT void spifns_clear_last_error(void);

Expand Down Expand Up @@ -212,7 +212,7 @@ DLLEXPORT unsigned int spifns_count_streams(void);
DLLEXPORT int spifns_stream_init(spifns_stream_t *p_stream);
DLLEXPORT void spifns_stream_close(spifns_stream_t stream);
DLLEXPORT unsigned int spifns_count_streams(void);
DLLEXPORT int spifns_stream_sequence(spifns_stream_t stream, SPISEQ_1_4 *pSequence, int nCount);
DLLEXPORT int spifns_stream_sequence(spifns_stream_t stream, void *pSequence, int nCount);
DLLEXPORT const char* spifns_stream_command(spifns_stream_t stream, const char *command);
DLLEXPORT const char* spifns_stream_getvar(spifns_stream_t stream, const char *var);
DLLEXPORT void spifns_stream_chip_select(spifns_stream_t stream, int which);
Expand Down

0 comments on commit 835dc2d

Please sign in to comment.