/*
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
Copyright (C) 2016..2019 Thomas Schöpping et al.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_PCAL6524)) || defined(__DOXYGEN__)
#include
#include
/******************************************************************************/
/* LOCAL DEFINITIONS */
/******************************************************************************/
/******************************************************************************/
/* EXPORTED VARIABLES */
/******************************************************************************/
/******************************************************************************/
/* LOCAL TYPES */
/******************************************************************************/
/******************************************************************************/
/* LOCAL VARIABLES */
/******************************************************************************/
/******************************************************************************/
/* LOCAL FUNCTIONS */
/******************************************************************************/
/******************************************************************************/
/* EXPORTED FUNCTIONS */
/******************************************************************************/
aos_utresult_t utAlldPcal6524Func(BaseSequentialStream* stream, aos_unittest_t *ut)
{
aosDbgCheck((ut->data != NULL) &&
(((ut_pcal6524data_t*)ut->data)->pcal6524d != NULL));
// local variables
aos_utresult_t result = {0, 0};
uint32_t status;
uint8_t buffer[24];
memset(buffer, 0xAA, sizeof(buffer));
// This test is currently not supported. See PCAL6524 driver implementation for further information.
// chprintf(stream, "reading device ID...\n");
// status = pcal6524_lld_read_id(((ut_pcal6524data_t*)ut->data)->pcal6524d, buffer, ((ut_pcal6524data_t*)ut->data)->timeout);
// chprintf(stream, "\t\traw: 0x%02X 0x%02X 0x%02X\n", buffer[0], buffer[1], buffer[2]);
// chprintf(stream, "\t\tname: 0x%03X\n", ((pcal6524_lld_deviceid_t*)buffer)->name);
// chprintf(stream, "\t\tpart: 0x%03X\n", ((pcal6524_lld_deviceid_t*)buffer)->part);
// chprintf(stream, "\t\trevision: 0x%01X\n", ((pcal6524_lld_deviceid_t*)buffer)->revision);
// if ((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) {
// aosUtPassed(stream, &result);
// } else {
// aosUtFailedMsg(stream, &result, "0x%08X\n", status);
// }
chprintf(stream, "reading register...\n");
status = pcal6524_lld_read_reg(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, buffer, ((ut_pcal6524data_t*)ut->data)->timeout);
chprintf(stream, "\t\tdebounce count: %u\n", buffer[0]);
if ((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) {
aosUtPassed(stream, &result);
} else {
aosUtFailedMsg(stream, &result, "0x%08X\n", status);
}
chprintf(stream, "writing register...\n");
buffer[3] = 0xFF;
status = pcal6524_lld_write_reg(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, buffer[3], ((ut_pcal6524data_t*)ut->data)->timeout);
status |= pcal6524_lld_read_reg(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, &buffer[4], ((ut_pcal6524data_t*)ut->data)->timeout);
status |= pcal6524_lld_write_reg(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, buffer[0], ((ut_pcal6524data_t*)ut->data)->timeout);
status |= pcal6524_lld_read_reg(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, &buffer[1], ((ut_pcal6524data_t*)ut->data)->timeout);
if (((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) &&
((buffer[1] == buffer[0]) && (buffer[4] == buffer[3]))) {
aosUtPassed(stream, &result);
} else {
aosUtFailedMsg(stream, &result, "0x%08X\n", status);
}
chprintf(stream, "reading group...\n");
status = pcal6524_lld_read_group(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, buffer, ((ut_pcal6524data_t*)ut->data)->timeout);
chprintf(stream, "\t\toutput drive strength: 0x%04X 0x%04X 0x%04X\n",
(((uint16_t)buffer[0]) << 8) | buffer[1],
(((uint16_t)buffer[2]) << 8) | buffer[3],
(((uint16_t)buffer[4]) << 8) | buffer[5]);
if ((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) {
aosUtPassed(stream, &result);
} else {
aosUtFailedMsg(stream, &result, "0x%08X\n", status);
}
chprintf(stream, "writing group...\n");
memset(&buffer[6], PCAL6524_LL_OUTPUTDRIVESTRENGTH_0_25, 6);
status = pcal6524_lld_write_group(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, &buffer[6], ((ut_pcal6524data_t*)ut->data)->timeout);
status |= pcal6524_lld_read_group(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, &buffer[12], ((ut_pcal6524data_t*)ut->data)->timeout);
status |= pcal6524_lld_write_group(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, &buffer[0], ((ut_pcal6524data_t*)ut->data)->timeout);
status |= pcal6524_lld_read_group(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, &buffer[18], ((ut_pcal6524data_t*)ut->data)->timeout);
if (((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) &&
((memcmp(&buffer[12], &buffer[6], 6) == 0) && (memcmp(&buffer[18], &buffer[0], 6) == 0))) {
aosUtPassed(stream, &result);
} else {
aosUtFailedMsg(stream, &result, "0x%08X\n", status);
}
chprintf(stream, "reading continuously...\n");
// read the following registers continously (24 bytes):
// output 0-3 + polarity inversions 0-3 + configuration 0-3 + output drive strength 0A-2B + input latch 0-3 + pupd enable 0-3 + pupd selection 0-3
status = pcal6524_lld_read_continuous(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUT_P0, buffer, 24, ((ut_pcal6524data_t*)ut->data)->timeout);
chprintf(stream, "\t\toutput: 0x%02X 0x%02X 0x%02X\n", buffer[0], buffer[1], buffer[2]);
chprintf(stream, "\t\tpolarity inversion: 0x%02X 0x%02X 0x%02X\n", buffer[3], buffer[4], buffer[5]);
chprintf(stream, "\t\tconfiguration: 0x%02X 0x%02X 0x%02X\n", buffer[6], buffer[7], buffer[8]);
chprintf(stream, "\t\toutput drive strength: 0x%04X 0x%04X 0x%04X\n",
(((uint16_t)buffer[9]) << 8) | buffer[10],
(((uint16_t)buffer[11]) << 8) | buffer[12],
(((uint16_t)buffer[13]) << 8) | buffer[14]);
chprintf(stream, "\t\tinput latch: 0x%02X 0x%02X 0x%02X\n", buffer[15], buffer[16], buffer[17]);
chprintf(stream, "\t\tpupd enable: 0x%02X 0x%02X 0x%02X\n", buffer[18], buffer[19], buffer[20]);
chprintf(stream, "\t\tpupd selection: 0x%02X 0x%02X 0x%02X\n", buffer[21], buffer[22], buffer[23]);
if ((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) {
aosUtPassed(stream, &result);
} else {
aosUtFailedMsg(stream, &result, "0x%08X\n", status);
}
chprintf(stream, "writing continuously...\n");
{
uint8_t writebuffer[24];
uint8_t readbuffer[2][24];
// copy the read configuration but set the output drive strength to factor 0.25
memcpy(writebuffer, buffer, sizeof(buffer));
memset(&writebuffer[9], PCAL6524_LL_OUTPUTDRIVESTRENGTH_0_25, 6);
status = pcal6524_lld_write_continuous(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUT_P0, writebuffer, 24, ((ut_pcal6524data_t*)ut->data)->timeout);
status |= pcal6524_lld_read_continuous(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUT_P0, readbuffer[0], 24, ((ut_pcal6524data_t*)ut->data)->timeout);
status |= pcal6524_lld_write_continuous(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUT_P0, buffer, 24, ((ut_pcal6524data_t*)ut->data)->timeout);
status |= pcal6524_lld_read_continuous(((ut_pcal6524data_t*)ut->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUT_P0, readbuffer[1], 24, ((ut_pcal6524data_t*)ut->data)->timeout);
if (((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) &&
((memcmp(writebuffer, readbuffer[0], 24) == 0) && (memcmp(buffer, readbuffer[1], 24) == 0))) {
aosUtPassed(stream, &result);
} else {
aosUtFailedMsg(stream, &result, "0x%08X\n", status);
}
}
aosUtInfoMsg(stream, "driver object memory footprint: %u bytes\n", sizeof(PCAL6524Driver));
return result;
}
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_PCAL6524) */