Give each GPIO its own function

This also seemed to fix the grey screen at boot up, likly due to setting special function bits to 0 with P*SEL registers.
This commit is contained in:
meepingsnesroms
2018-07-28 11:58:36 -07:00
parent a753dd7435
commit 92368980b7
3 changed files with 73 additions and 26 deletions

View File

@@ -55,7 +55,7 @@ bool ads7846ExchangeBit(bool bitIn){
switch(powerSave){
case 0:
case 1:
//normal touchscreen operation
//touchscreen data only
switch(channel){
case 0:
//temperature 0, wrong mode
@@ -120,7 +120,7 @@ bool ads7846ExchangeBit(bool bitIn){
break;
case 3:
//non touchscreen data
//all data
if(!palmInput.touchscreenTouched){
switch(channel){
case 0:
@@ -129,8 +129,11 @@ bool ads7846ExchangeBit(bool bitIn){
break;
case 1:
//touchscreen y, wrong mode
ads7846OutputValue = 0xFFF;
//touchscreen y
if(palmInput.touchscreenTouched)
ads7846OutputValue = 0x7DC;//ads7846OutputValue = ads7846RangeMap(0, 219, 219 - palmInput.touchscreenY, 0x0EE, 0xEE4);
else
ads7846OutputValue = 0xFFF;//y is almost fully on when dorment
break;
case 2:
@@ -140,18 +143,27 @@ bool ads7846ExchangeBit(bool bitIn){
break;
case 3:
//touchscreen x relative to y, wrong mode
ads7846OutputValue = 0x000;
//touchscreen x relative to y
if(palmInput.touchscreenTouched)
ads7846OutputValue = 0x5BF;//ads7846OutputValue = ads7846RangeMap(0, 159, 159 - palmInput.touchscreenX, 0x093, 0x600) + ads7846RangeMap(0, 219, 219 - palmInput.touchscreenY, 0x000, 0x280);
else
ads7846OutputValue = 0x000;
break;
case 4:
//touchscreen y relative to x, wrong mode
ads7846OutputValue = 0xFFF;
//touchscreen y relative to x
if(palmInput.touchscreenTouched)
ads7846OutputValue = 0xD5B;//ads7846OutputValue = ads7846RangeMap(0, 219, 219 - palmInput.touchscreenY, 0x9AF, 0xF3F) + ads7846RangeMap(0, 159, 159 - palmInput.touchscreenX, 0x000, 0x150);
else
ads7846OutputValue = 0xFFF;
break;
case 5:
//touchscreen x, wrong mode
ads7846OutputValue = 0x000;
//touchscreen x
if(palmInput.touchscreenTouched)
ads7846OutputValue = 0xD0D;//ads7846OutputValue = ads7846RangeMap(0, 159, 159 - palmInput.touchscreenX, 0x0FD, 0xF47);
else
ads7846OutputValue = 0x3FB;
break;
case 6:

View File

@@ -40,7 +40,7 @@ bool pllIsOn(){
}
bool backlightAmplifierState(){
return registerArrayRead8(PKDATA) & registerArrayRead8(PKSEL) & registerArrayRead8(PKDIR) & 0x02;
return getPortKValue() & 0x02;
}
bool registersAreXXFFMapped(){
@@ -358,23 +358,19 @@ uint8_t getHwRegister8(uint32_t address){
switch(address){
case PADATA:
//not attached, used as data lines
return 0x00;
return getPortAValue();
case PBDATA:
//read outputs as is and inputs as true, floating pins are high
return (registerArrayRead8(PBDATA) & registerArrayRead8(PBDIR)) | ~registerArrayRead8(PBDIR);
return getPortBValue();
case PCDATA:
//read outputs as is and inputs as false, floating pins are low, port c has a pull down not up
return registerArrayRead8(PCDATA) & registerArrayRead8(PCDIR);
return getPortCValue();
case PDDATA:
return getPortDValue();
case PEDATA:
//read outputs as is and inputs as true, floating pins are high
return (registerArrayRead8(PEDATA) & registerArrayRead8(PEDIR)) | ~registerArrayRead8(PEDIR);
return getPortEValue();
case PFDATA:
return getPortFValue();
@@ -383,15 +379,13 @@ uint8_t getHwRegister8(uint32_t address){
return getPortGValue();
case PJDATA:
//read outputs as is and inputs as true, floating pins are high
return (registerArrayRead8(PJDATA) & registerArrayRead8(PJDIR)) | ~registerArrayRead8(PJDIR);
return getPortJValue();
case PKDATA:
return getPortKValue();
case PMDATA:
//read outputs as is and inputs as true, floating pins are high
return (registerArrayRead8(PMDATA) & registerArrayRead8(PMDIR)) | ~registerArrayRead8(PMDIR);
return getPortMValue();
//basic non GPIO functions
case LCKCON:

View File

@@ -1,3 +1,15 @@
//declare I/O port functions in advance
static inline uint8_t getPortAValue();
static inline uint8_t getPortBValue();
static inline uint8_t getPortCValue();
static inline uint8_t getPortDValue();
static inline uint8_t getPortEValue();
static inline uint8_t getPortFValue();
static inline uint8_t getPortGValue();
static inline uint8_t getPortJValue();
static inline uint8_t getPortKValue();
static inline uint8_t getPortMValue();
//basic accessors
static inline uint8_t registerArrayRead8(uint32_t address){return BUFFER_READ_8(palmReg, address, 0, 0xFFF);}
static inline uint16_t registerArrayRead16(uint32_t address){return BUFFER_READ_16(palmReg, address, 0, 0xFFF);}
@@ -252,6 +264,7 @@ static inline void setSpiCont2(uint16_t value){
uint8_t bitCount = (value & 0x000F) + 1;
uint16_t startBit = 1 << (bitCount - 1);
uint16_t spi2Data = registerArrayRead16(SPIDATA2);
bool ads7846ChipSelect = getPortGValue() & 0x04;
//uint16_t oldSpi2Data = spi2Data;
//the input data is shifted into the unused bits if the transfer is less than 16 bits
@@ -376,7 +389,8 @@ static inline void setIsr(uint32_t value, bool useTopWord, bool useBottomWord){
//register getters
static inline uint8_t getPortDInputPinValues(){
uint8_t requestedRow = ~(registerArrayRead8(PKDIR) & registerArrayRead8(PKDATA));//keys are requested on port k(set low to enable) and read on port d
//uint8_t requestedRow = ~(registerArrayRead8(PKDATA) & registerArrayRead8(PKSEL) & registerArrayRead8(PKDIR));//keys are requested on port k(set low to enable) and read on port d
uint8_t requestedRow = ~getPortKValue();
uint8_t portDInputValues = 0x00;
//portDInputValues |= 0x80;//battery dead bit, dont know the proper level to set this
@@ -400,6 +414,20 @@ static inline uint8_t getPortDInputPinValues(){
return ~portDInputValues;
}
static inline uint8_t getPortAValue(){
//not attached, used as data lines
return 0x00;
}
static inline uint8_t getPortBValue(){
return ((registerArrayRead8(PBDATA) & registerArrayRead8(PBDIR)) | ~registerArrayRead8(PBDIR)) & registerArrayRead8(PBSEL);
}
static inline uint8_t getPortCValue(){
//port c uses pull downs not pull ups
return registerArrayRead8(PCDATA) & registerArrayRead8(PCDIR) & registerArrayRead8(PCSEL);
}
static inline uint8_t getPortDValue(){
uint8_t portDValue = getPortDInputPinValues();
uint8_t portDData = registerArrayRead8(PDDATA);
@@ -413,6 +441,10 @@ static inline uint8_t getPortDValue(){
return portDValue;
}
static inline uint8_t getPortEValue(){
return ((registerArrayRead8(PEDATA) & registerArrayRead8(PEDIR)) | ~registerArrayRead8(PEDIR)) & registerArrayRead8(PESEL);
}
static inline uint8_t getPortFValue(){
uint8_t portFValue = 0x00;
uint8_t portFData = registerArrayRead8(PKDATA);
@@ -443,6 +475,10 @@ static inline uint8_t getPortGValue(){
return portGValue;
}
static inline uint8_t getPortJValue(){
return ((registerArrayRead8(PJDATA) & registerArrayRead8(PJDIR)) | ~registerArrayRead8(PJDIR)) & registerArrayRead8(PJSEL);
}
static inline uint8_t getPortKValue(){
uint8_t portKValue = 0x00;
uint8_t portKData = registerArrayRead8(PKDATA);
@@ -457,6 +493,11 @@ static inline uint8_t getPortKValue(){
return portKValue;
}
static inline uint8_t getPortMValue(){
//bit 5 has a pull up not pull down, bits 4-0 have a pull down, bit 7-6 are not active at all
return ((registerArrayRead8(PMDATA) & registerArrayRead8(PMDIR)) | (~registerArrayRead8(PMDIR) & 0x20)) & registerArrayRead8(PMSEL);
}
static inline uint16_t getSpiTest(){
//SSTATUS is unemulated because the datasheet has no descrption of how it works
return spi1RxPosition << 4 | spi1TxPosition;
@@ -480,11 +521,11 @@ static inline uint16_t getPwmc1(){
//updaters
static inline void updatePowerButtonLedStatus(){
palmMisc.powerButtonLed = (bool)(registerArrayRead8(PBDATA) & registerArrayRead8(PBSEL) & registerArrayRead8(PBDIR) & 0x40) != palmMisc.batteryCharging;
palmMisc.powerButtonLed = (bool)(getPortBValue() & 0x40) != palmMisc.batteryCharging;
}
static inline void updateVibratorStatus(){
palmMisc.vibratorOn = registerArrayRead8(PKDATA) & registerArrayRead8(PKSEL) & registerArrayRead8(PKDIR) & 0x10;
palmMisc.vibratorOn = getPortKValue() & 0x10;
}
static inline void updateBacklightAmplifierStatus(){