mirror of
https://github.com/preble/libpinproc
synced 2026-02-24 18:25:23 +01:00
Added support for DMD frame events and new switch event enable.
This commit is contained in:
135
src/PRDevice.cpp
135
src/PRDevice.cpp
@@ -73,6 +73,16 @@ PRResult PRDevice::Reset(uint32_t resetFlags)
|
||||
|
||||
DriverLoadMachineTypeDefaults(machineType, resetFlags);
|
||||
|
||||
// Disable dmd events if updating the device.
|
||||
#if 0
|
||||
if (resetFlags & kPRResetFlagUpdateDevice)
|
||||
{
|
||||
PRDMDConfig *dmdConfig = &(this->dmdConfig);
|
||||
dmdConfig->enableFrameEvents = false;
|
||||
DMDUpdateConfig(dmdConfig);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Make sure the free list is empty.
|
||||
while (!freeSwitchRuleIndexes.empty()) freeSwitchRuleIndexes.pop();
|
||||
|
||||
@@ -121,11 +131,28 @@ int PRDevice::GetEvents(PREvent *events, int maxEvents)
|
||||
|
||||
events[i].value = event_data & P_ROC_EVENT_SWITCH_NUM_MASK;
|
||||
bool open = (event_data & P_ROC_EVENT_SWITCH_STATE_MASK) >> P_ROC_EVENT_SWITCH_STATE_SHIFT;
|
||||
bool debounced = (event_data & P_ROC_EVENT_SWITCH_DEBOUNCED_MASK) >> P_ROC_EVENT_SWITCH_DEBOUNCED_SHIFT;
|
||||
if (open)
|
||||
events[i].type = debounced ? kPREventTypeSwitchOpenDebounced : kPREventTypeSwitchOpenNondebounced;
|
||||
else
|
||||
events[i].type = debounced ? kPREventTypeSwitchClosedDebounced : kPREventTypeSwitchOpenNondebounced;
|
||||
|
||||
switch ((event_data & P_ROC_EVENT_TYPE_MASK) >> P_ROC_EVENT_TYPE_SHIFT)
|
||||
{
|
||||
case P_ROC_EVENT_TYPE_SWITCH:
|
||||
{
|
||||
bool debounced = (event_data & P_ROC_EVENT_SWITCH_DEBOUNCED_MASK) >> P_ROC_EVENT_SWITCH_DEBOUNCED_SHIFT;
|
||||
if (open)
|
||||
events[i].type = debounced ? kPREventTypeSwitchOpenDebounced : kPREventTypeSwitchOpenNondebounced;
|
||||
else
|
||||
events[i].type = debounced ? kPREventTypeSwitchClosedDebounced : kPREventTypeSwitchOpenNondebounced;
|
||||
break;
|
||||
}
|
||||
|
||||
case P_ROC_EVENT_TYPE_DMD:
|
||||
{
|
||||
events[i].type = kPREventTypeDMDFrameDisplayed;
|
||||
break;
|
||||
}
|
||||
|
||||
default: events[i].type = kPREventTypeInvalid;
|
||||
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
@@ -385,7 +412,7 @@ PRSwitchRuleInternal *PRDevice::GetSwitchRuleByIndex(uint16_t index)
|
||||
PRResult PRDevice::SwitchUpdateConfig(PRSwitchConfig *switchConfig)
|
||||
{
|
||||
uint32_t rc;
|
||||
const int burstWords = 2;
|
||||
const int burstWords = 4;
|
||||
uint32_t burst[burstWords];
|
||||
|
||||
this->switchConfig = *switchConfig;
|
||||
@@ -602,25 +629,41 @@ PRResult PRDevice::DMDDraw(uint8_t * dots)
|
||||
|
||||
// The following code prints out the init lines for the 4 Xilinx BlockRAMs
|
||||
// in the FPGA. It's used to make an image for the P-ROC to display on power-up.
|
||||
//if (print_dots) {
|
||||
//print_dots = false;
|
||||
|
||||
//for (i=0; i<4; i++) {
|
||||
// std::cout << "For memory: "<< i << "\n";
|
||||
// // Need 4 lines to get 1 frame (4*256*4 = 4096)
|
||||
// // The rest will be all 0.
|
||||
// for (y=0; y<4; y++) {
|
||||
// std::cout << "defparam blockram.INIT_00 = 256'b";
|
||||
// for (j=31; j>=0; j--) {
|
||||
// for (x=7; x>=0; x--) {
|
||||
// std::cout << ((dmd_frame_buffer[(y*32)+j] >> ((i*8)+x)) & 1);
|
||||
// }
|
||||
// }
|
||||
// std::cout << ";\n";
|
||||
// }
|
||||
// std::cout << "\n\n\n";
|
||||
//}
|
||||
//}
|
||||
#if 0
|
||||
// This is the original version... needs to be deleted.
|
||||
for (i=0; i<4; i++) {
|
||||
std::cout << "For memory: "<< i << "\n";
|
||||
// Need 4 lines to get 1 frame (4*256*4 = 4096)
|
||||
// The rest will be all 0.
|
||||
for (y=0; y<4; y++) {
|
||||
std::cout << "defparam blockram.INIT_00 = 256'b";
|
||||
for (j=31; j>=0; j--) {
|
||||
for (x=7; x>=0; x--) {
|
||||
std::cout << ((dmd_frame_buffer[(y*32)+j] >> ((i*8)+x)) & 1);
|
||||
}
|
||||
}
|
||||
std::cout << ";\n";
|
||||
}
|
||||
std::cout << "\n\n\n";
|
||||
}
|
||||
#endif
|
||||
#if 0
|
||||
for (i=0; i<4; i++) {
|
||||
std::cout << "For memory: "<< i << "\n";
|
||||
// Need 4 lines to get 1 frame (4*256*4 = 4096)
|
||||
// The rest will be all 0.
|
||||
for (y=0; y<4; y++) {
|
||||
std::cout << "defparam blockram.INIT_00 = 256'b";
|
||||
for (j=8; j>=0; j--) {
|
||||
for (x=31; x>=0; x--) {
|
||||
std::cout << ((dmd_frame_buffer[(y*32)+j] >> ((i*8)+x)) & 1);
|
||||
}
|
||||
}
|
||||
std::cout << ";\n";
|
||||
}
|
||||
std::cout << "\n\n\n";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
PRResult PRDevice::PRJTAGDriveOutputs(PRJTAGOutputs * jtagOutputs, bool_t toggleClk)
|
||||
@@ -674,12 +717,39 @@ PRResult PRDevice::PRJTAGGetStatus(PRJTAGStatus * status)
|
||||
|
||||
PRResult PRDevice::Open()
|
||||
{
|
||||
uint32_t temp_word;
|
||||
PRResult res = PRHardwareOpen();
|
||||
if (res == kPRSuccess)
|
||||
{
|
||||
// Try to verify the P-ROC IS in the FPGA before initializing the FPGA's FTDI interface
|
||||
// just in case it was already initialized from a previous application execution.
|
||||
DEBUG(PRLog(kPRLogInfo, "Verifying P-ROC ID: \n"));
|
||||
|
||||
// Attempt to turn off events. This is necessary if P-ROC wasn't shut down
|
||||
// properly previously. If the P-ROC isn't initialized, this request will
|
||||
// be ignored.
|
||||
|
||||
PRDMDConfig dmdConfig;
|
||||
dmdConfig.numRows = 32; // Doesn't matter.
|
||||
dmdConfig.numColumns = 128; // Doesn't matter
|
||||
dmdConfig.numSubFrames = 4; // Doesn't matter
|
||||
dmdConfig.numFrameBuffers = 3; // Doesn't matter
|
||||
dmdConfig.autoIncBufferWrPtr = false;
|
||||
dmdConfig.enableFrameEvents = false;
|
||||
DMDUpdateConfig(&dmdConfig);
|
||||
|
||||
PRSwitchConfig switchConfig;
|
||||
switchConfig.clear = false;
|
||||
switchConfig.hostEventsEnable = false;
|
||||
switchConfig.directMatrixScanLoopTime = 2; // milliseconds
|
||||
switchConfig.pulsesBeforeCheckingRX = 10;
|
||||
switchConfig.inactivePulsesAfterBurst = 12;
|
||||
switchConfig.pulsesPerBurst = 6;
|
||||
switchConfig.pulseHalfPeriodTime = 13; // milliseconds
|
||||
SwitchUpdateConfig(&switchConfig);
|
||||
|
||||
// Flush read data to ensure VerifyChipID starts with clean buffer.
|
||||
res = FlushReadBuffer();
|
||||
if (VerifyChipID() == kPRFailure) {
|
||||
// Since the FPGA didn't appear to be responding properly, send the FPGA's FTDI
|
||||
// initialization sequence. This is a set of bytes the FPGA is waiting to receive
|
||||
@@ -687,7 +757,7 @@ PRResult PRDevice::Open()
|
||||
// in and wreaking havoc before software is up and running.
|
||||
DEBUG(PRLog(kPRLogInfo, "Initializing P-ROC...\n"));
|
||||
res = FlushReadBuffer();
|
||||
uint32_t temp_word = P_ROC_INIT_PATTERN_A;
|
||||
temp_word = P_ROC_INIT_PATTERN_A;
|
||||
res = WriteData(&temp_word, 1);
|
||||
temp_word = P_ROC_INIT_PATTERN_B;
|
||||
res = WriteData(&temp_word, 1);
|
||||
@@ -695,6 +765,7 @@ PRResult PRDevice::Open()
|
||||
if (res == kPRFailure)
|
||||
DEBUG(PRLog(kPRLogWarning, "Unable to read Chip ID - P-ROC could not be initialized.\n"));
|
||||
}
|
||||
else res = kPRSuccess;
|
||||
}
|
||||
|
||||
return res;
|
||||
@@ -914,10 +985,14 @@ PRResult PRDevice::FlushReadBuffer()
|
||||
numBytes = CollectReadData();
|
||||
k = 0;
|
||||
//std::cout << "Flushing rd buffer of " << num_words << "words\n";
|
||||
while (k < numBytes) {
|
||||
rc = ReadData(rd_buffer, 1);
|
||||
k++;
|
||||
}
|
||||
|
||||
//while (k < numBytes) {
|
||||
// rc = ReadData(rd_buffer, 1);
|
||||
// k++;
|
||||
//}
|
||||
collected_bytes_rd_addr = 0;
|
||||
collected_bytes_wr_addr = 0;
|
||||
num_collected_bytes = 0;
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -157,6 +157,9 @@ int32_t CreateSwitchUpdateConfigBurst ( uint32_t * burst, PRSwitchConfig *switch
|
||||
P_ROC_SWITCH_CONFIG_PULSES_PER_BURST_SHIFT) |
|
||||
(switchConfig->pulseHalfPeriodTime <<
|
||||
P_ROC_SWITCH_CONFIG_MS_PER_PULSE_HALF_PERIOD_SHIFT);
|
||||
burst[2] = CreateBurstCommand (P_ROC_BUS_STATE_CHANGE_PROC_SELECT,
|
||||
P_ROC_STATE_CHANGE_CONFIG_ADDR, 1 );
|
||||
burst[3] = switchConfig->hostEventsEnable;
|
||||
|
||||
return kPRSuccess;
|
||||
}
|
||||
@@ -218,6 +221,9 @@ int32_t CreateDMDUpdateConfigBurst ( uint32_t * burst, PRDMDConfig *dmd_config)
|
||||
addr = 0;
|
||||
burst[0] = CreateBurstCommand (P_ROC_BUS_DMD_SELECT, addr, 1 );
|
||||
burst[1] = (1 << P_ROC_DMD_ENABLE_SHIFT) |
|
||||
(dmd_config->enableFrameEvents << P_ROC_DMD_ENABLE_FRAME_EVENTS_SHIFT) |
|
||||
(dmd_config->autoIncBufferWrPtr << P_ROC_DMD_AUTO_INC_WR_POINTER_SHIFT) |
|
||||
(dmd_config->numFrameBuffers << P_ROC_DMD_NUM_FRAME_BUFFERS_SHIFT) |
|
||||
(dmd_config->numSubFrames << P_ROC_DMD_NUM_SUB_FRAMES_SHIFT) |
|
||||
(dmd_config->numRows << P_ROC_DMD_NUM_ROWS_SHIFT) |
|
||||
(dmd_config->numColumns << P_ROC_DMD_NUM_COLUMNS_SHIFT);
|
||||
|
||||
@@ -110,6 +110,10 @@ const uint32_t P_ROC_JTAG_TDI_MEMORY_BASE_ADDR = 0x800;
|
||||
const uint32_t P_ROC_SWITCH_CTRL_STATE_BASE_ADDR = 4;
|
||||
const uint32_t P_ROC_SWITCH_CTRL_DEBOUNCE_BASE_ADDR = 11;
|
||||
|
||||
const uint32_t P_ROC_EVENT_TYPE_SWITCH = 0;
|
||||
const uint32_t P_ROC_EVENT_TYPE_DMD = 1;
|
||||
const uint32_t P_ROC_EVENT_TYPE_MASK = 0xC00;
|
||||
const uint32_t P_ROC_EVENT_TYPE_SHIFT = 10;
|
||||
const uint32_t P_ROC_EVENT_SWITCH_NUM_MASK = 0xFF;
|
||||
const uint32_t P_ROC_EVENT_SWITCH_STATE_MASK = 0x100;
|
||||
const uint32_t P_ROC_EVENT_SWITCH_STATE_SHIFT = 8;
|
||||
@@ -176,9 +180,14 @@ const uint32_t P_ROC_SWITCH_RULE_LINK_ADDRESS_SHIFT = 11;
|
||||
const uint32_t P_ROC_SWITCH_RULE_CHANGE_OUTPUT_SHIFT = 9;
|
||||
const uint32_t P_ROC_SWITCH_RULE_DRIVER_NUM_SHIFT = 0;
|
||||
|
||||
const uint32_t P_ROC_STATE_CHANGE_CONFIG_ADDR = 0x1000;
|
||||
|
||||
const uint32_t P_ROC_DMD_NUM_COLUMNS_SHIFT = 0;
|
||||
const uint32_t P_ROC_DMD_NUM_ROWS_SHIFT = 8;
|
||||
const uint32_t P_ROC_DMD_NUM_SUB_FRAMES_SHIFT = 16;
|
||||
const uint32_t P_ROC_DMD_NUM_FRAME_BUFFERS_SHIFT = 24;
|
||||
const uint32_t P_ROC_DMD_AUTO_INC_WR_POINTER_SHIFT = 29;
|
||||
const uint32_t P_ROC_DMD_ENABLE_FRAME_EVENTS_SHIFT = 30;
|
||||
const uint32_t P_ROC_DMD_ENABLE_SHIFT = 31;
|
||||
|
||||
const uint32_t P_ROC_DMD_DOTCLK_HALF_PERIOD_SHIFT = 0;
|
||||
|
||||
Reference in New Issue
Block a user