mirror of
https://github.com/stratosonic/Apple-II-Joystick-to-USB-Adapter.git
synced 2024-06-16 02:29:30 +00:00
106 lines
3.6 KiB
C
106 lines
3.6 KiB
C
|
/********************************************************************
|
||
|
Software License Agreement:
|
||
|
|
||
|
The software supplied herewith by Microchip Technology Incorporated
|
||
|
(the "Company") for its PIC(R) Microcontroller is intended and
|
||
|
supplied to you, the Company's customer, for use solely and
|
||
|
exclusively on Microchip PIC Microcontroller products. The
|
||
|
software is owned by the Company and/or its supplier, and is
|
||
|
protected under applicable copyright laws. All rights are reserved.
|
||
|
Any use in violation of the foregoing restrictions may subject the
|
||
|
user to criminal sanctions under applicable laws, as well as to
|
||
|
civil liability for the breach of the terms and conditions of this
|
||
|
license.
|
||
|
|
||
|
THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
|
||
|
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
|
||
|
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||
|
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
|
||
|
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
|
||
|
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
|
||
|
*******************************************************************/
|
||
|
|
||
|
#include <xc.h>
|
||
|
#include <stdbool.h>
|
||
|
#include <buttons.h>
|
||
|
|
||
|
/*** Button Definitions *********************************************/
|
||
|
#define S1_PORT PORTCbits.RC0
|
||
|
#define S2_PORT PORTCbits.RC1
|
||
|
|
||
|
#define S1_TRIS TRISCbits.TRISC0
|
||
|
#define S2_TRIS TRISCbits.TRISC1
|
||
|
|
||
|
#define BUTTON_PRESSED 1
|
||
|
#define BUTTON_NOT_PRESSED 0
|
||
|
|
||
|
#define PIN_INPUT 1
|
||
|
#define PIN_OUTPUT 0
|
||
|
|
||
|
#define PIN_DIGITAL 0
|
||
|
#define PIN_ANALOG 1
|
||
|
|
||
|
/*********************************************************************
|
||
|
* Function: bool BUTTON_IsPressed(BUTTON button);
|
||
|
*
|
||
|
* Overview: Returns the current state of the requested button
|
||
|
*
|
||
|
* PreCondition: button configured via BUTTON_SetConfiguration()
|
||
|
*
|
||
|
* Input: BUTTON button - enumeration of the buttons available in
|
||
|
* this demo. They should be meaningful names and not the names
|
||
|
* of the buttons on the silkscreen on the board (as the demo
|
||
|
* code may be ported to other boards).
|
||
|
* i.e. - ButtonIsPressed(BUTTON_SEND_MESSAGE);
|
||
|
*
|
||
|
* Output: TRUE if pressed; FALSE if not pressed.
|
||
|
*
|
||
|
********************************************************************/
|
||
|
bool BUTTON_IsPressed(BUTTON button) {
|
||
|
switch (button) {
|
||
|
case BUTTON_S1:
|
||
|
return ( (S1_PORT == BUTTON_PRESSED) ? true : false);
|
||
|
|
||
|
case BUTTON_S2:
|
||
|
return ( (S2_PORT == BUTTON_PRESSED) ? true : false);
|
||
|
|
||
|
case BUTTON_NONE:
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/*********************************************************************
|
||
|
* Function: void BUTTON_Enable(BUTTON button);
|
||
|
*
|
||
|
* Overview: Returns the current state of the requested button
|
||
|
*
|
||
|
* PreCondition: button configured via BUTTON_SetConfiguration()
|
||
|
*
|
||
|
* Input: BUTTON button - enumeration of the buttons available in
|
||
|
* this demo. They should be meaningful names and not the names
|
||
|
* of the buttons on the silkscreen on the board (as the demo
|
||
|
* code may be ported to other boards).
|
||
|
* i.e. - ButtonIsPressed(BUTTON_SEND_MESSAGE);
|
||
|
*
|
||
|
* Output: None
|
||
|
*
|
||
|
********************************************************************/
|
||
|
void BUTTON_Enable(BUTTON button) {
|
||
|
switch (button) {
|
||
|
case BUTTON_S1:
|
||
|
S1_TRIS = PIN_INPUT;
|
||
|
ANSELbits.ANS4 = PIN_DIGITAL;
|
||
|
break;
|
||
|
|
||
|
case BUTTON_S2:
|
||
|
S2_TRIS = PIN_INPUT;
|
||
|
ANSELbits.ANS5 = PIN_DIGITAL;
|
||
|
break;
|
||
|
|
||
|
case BUTTON_NONE:
|
||
|
break;
|
||
|
}
|
||
|
}
|