Exemplo n.º 1
0
CyU3PReturnStatus_t ep0_rdwr_setup() {
    // Fetch the rdwr command  
    // NOTE this api call acks the vendor command if it's successful
    CyU3PReturnStatus_t status = CyU3PUsbGetEP0Data(sizeof(rdwr_data_header_t), glEp0Buffer, 0);

    if(status != CY_U3P_SUCCESS){
      log_error("Error get EP0 Data\n", status);
      return status;
    }
    CyU3PMemCopy ( (uint8_t*)&gRdwrCmd.header, glEp0Buffer, sizeof(gRdwrCmd.header) );
    return CY_U3P_SUCCESS;
}
uint16_t uxn1330_read(CyU3PDmaBuffer_t* pBuf) {
 memset(pBuf->buffer,0,gRdwrCmd.header.transfer_length);
 switch ( gRdwrCmd.header.reg_addr ) {
    case UXN1330_VERSION:
        {
            uint32_t version=VERSION;
            CyU3PMemCopy( pBuf->buffer, (uint8_t*)&version, sizeof(version) );
            return 0;
        }
    case UXN1330_LP_B:
    case UXN1330_V18_EN:
    case UXN1330_VCON_EN:
        { 
            CyBool_t val;
            CyU3PReturnStatus_t ret;
            ret=CyU3PGpioGetValue( gRdwrCmd.header.reg_addr, &val );
            log_debug ( "gpio pin %d val: %d\n", gRdwrCmd.header.reg_addr, val );
            if (ret == CY_U3P_SUCCESS) {
                pBuf->buffer[0] = val; 
                pBuf->buffer[1] = 0;
                return 0;
            } else {
                log_error ( "gpio read failed: %d\n", ret );
            }
        }
        break;
    case UXN1330_VCON_POT:
        {
            uint8_t val;
            uint16_t ret=rdwr_vcon_pot(&val,CyFalse);
            if (ret == CY_U3P_SUCCESS) {
                pBuf->buffer[0] = val;
                pBuf->buffer[1] = 0;
                return 0;
            }
            return ret;
        }
        break;
    default:
        log_info("Unhandled UXN1330 read reg addr: %d\n", gRdwrCmd.header.reg_addr );
 }
 return 1;
}