Skip to content

Commit

Permalink
Change Wiegand output to Virtual Serial Port
Browse files Browse the repository at this point in the history
  • Loading branch information
jpliew committed Nov 15, 2013
1 parent 2136b6a commit 0325d34
Show file tree
Hide file tree
Showing 8 changed files with 749 additions and 561 deletions.
53 changes: 41 additions & 12 deletions Firmware/HardwareProfile - Low Pin Count USB Development Kit.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Software License Agreement:
The software supplied herewith by Microchip Technology Incorporated
(the “Company”) for its PIC® Microcontroller is intended and
(the “Company? for its PIC?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
Expand All @@ -19,7 +19,7 @@
civil liability for the breach of the terms and conditions of this
license.
THIS SOFTWARE IS PROVIDED IN AN “AS ISCONDITION. NO WARRANTIES,
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,
Expand Down Expand Up @@ -95,12 +95,17 @@
#define GetSystemClock() CLOCK_FREQ

/** LED ************************************************************/
#define mInitAllLEDs() LATC &= 0xF0; TRISC &= 0xF0;
#define mInitAllLEDs() LATC &= 0x00; TRISC &= 0x00;

#define mLED_1 LATCbits.LATC0
#define mLED_2 LATCbits.LATC1
#define mLED_3 LATCbits.LATC2
#define mLED_4 LATCbits.LATC3
#define mSHDN LATCbits.LATC6
#define mMUTE LATCbits.LATC7

//#define mRESET LATCbits.LATC3


#define mGetLED_1() mLED_1
#define mGetLED_2() mLED_2
Expand All @@ -111,39 +116,63 @@
#define mLED_2_On() mLED_2 = 1;
#define mLED_3_On() mLED_3 = 1;
#define mLED_4_On() mLED_4 = 1;

#define mSHDN_High() mSHDN = 1;
#define mMUTE_High() mMUTE = 1;

// #define mRESET_High() mRESET = 1;

#define mLED_1_Off() mLED_1 = 0;
#define mLED_2_Off() mLED_2 = 0;
#define mLED_3_Off() mLED_3 = 0;
#define mLED_4_Off() mLED_4 = 0;

#define mSHDN_Low() mSHDN = 0;
#define mMUTE_Low() mMUTE = 0;

// #define mRESET_Low() mRESET = 0;

#define mLED_1_Toggle() mLED_1 = !mLED_1;
#define mLED_2_Toggle() mLED_2 = !mLED_2;
#define mLED_3_Toggle() mLED_3 = !mLED_3;
#define mLED_4_Toggle() mLED_4 = !mLED_4;

/** SWITCH *********************************************************/
#define mInitSwitch2() //TRISAbits.TRISA3=1
#define mInitSwitch2() TRISAbits.TRISA3
//only one switch available so double duty
#define mInitSwitch3() //TRISAbits.TRISA3=1
#define mInitSwitch3() TRISAbits.TRISA3=1;
#define sw2 PORTAbits.RA3
#define sw3 PORTAbits.RA3
#define mInitAllSwitches() mInitSwitch2();
#define mInitAllSwitches() mInitSwitch2()

/** RS 232 lines ****************************************************/
#define UART_TRISTx TRISBbits.TRISB7
#define UART_TRISRx TRISBbits.TRISB5
#define UART_Tx PORTBbits.RB7
#define UART_Rx PORTBbits.RB5
#define UART_TRISRTS TRISBbits.TRISB4
#define UART_RTS PORTBbits.RB4
#define UART_TRISDTR TRISBbits.TRISB6
#define UART_DTR PORTBbits.RB6
#define UART_ENABLE RCSTAbits.SPEN
#define UART_ENABLE RCSTAbits.SPEN

/** I/O pin definitions ********************************************/
#define INPUT_PIN 1
#define OUTPUT_PIN 0

//These definitions are only relevant if the respective functions are enabled
//in the usb_config.h file.
//Make sure these definitions match the GPIO pins being used for your hardware
//setup.
#define UART_DTS PORTAbits.RA3
#define UART_DTR LATCbits.LATC3
#define UART_RTS LATCbits.LATC7
// #define UART_RTS LATBbits.LATB4
#define UART_CTS PORTBbits.RB6

//#define mInitRTSPin() {TRISBbits.TRISB4 = 0;} //Configure RTS as a digital output.
#define mInitRTSPin() {TRISCbits.TRISC7 = 0;} //Configure RTS as a digital output.

#define mInitCTSPin() {TRISBbits.TRISB6 = 1;} //Configure CTS as a digital input. (Make sure pin is digital if ANxx functions is present on the pin)
//#define mInitDTSPin() {TRISAbits.TRISA3 = 1;} //Configure DTS as a digital input. (Make sure pin is digital if ANxx functions is present on the pin)
#define mInitDTRPin() {TRISCbits.TRISC3 = 0;} //Configure DTR as a digital output.

/** Weigand pins ***************************************************/
//Set INT0 and INT2 to input
#define mTwiPinInit() TRISCbits.TRISC0 = 1; TRISCbits.TRISC2 = 1;
Expand All @@ -166,5 +195,5 @@
//65535-3000=62536=0xF448
#define mReloadTm0() TMR0H = 0xF4; TMR0L = 0x48;
//Enable timer and globle interrupt
#define mEnInt() INTCONbits.TMR0IE = 1; INTCONbits.GIE = 1;
#define mEnInt() INTCONbits.TMR0IE = 1; INTCONbits.GIE = 1;
#endif //HARDWARE_PROFILE_LOW_PIN_COUNT_USB_DEVELOPMENT_KIT_H
15 changes: 9 additions & 6 deletions Firmware/HardwareProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@
#include "HardwareProfile - PIC24F Starter Kit.h"
#elif defined(__PIC24FJ64GB004__)
#include "HardwareProfile - PIC24FJ64GB004 PIM.h"
#elif defined(__PIC24FJ64GB502__)
#include "HardwareProfile - PIC24FJ64GB502 Microstick.h"
#elif defined(__PIC24FJ256DA210__)
#include "HardwareProfile - PIC24FJ256DA210 Development Board.h"
#elif defined(__dsPIC33EP512MU810__)
#if defined(DSPIC33EP512MU810_PIM)
#include "HardwareProfile - dsPIC33EP512MU810 PIM.h"
#endif
#if defined(DSPIC33E_USB_STARTER_KIT)
#elif defined(DSPIC33E_USB_STARTER_KIT)
#include "HardwareProfile - dsPIC33E USB Starter Kit.h"
#endif
#elif defined(__PIC24EP512GU810__)
Expand All @@ -101,12 +102,14 @@
#include "HardwareProfile - PICDEM FSUSB.h"
#elif defined(__18F87J50)
#include "HardwareProfile - PIC18F87J50 PIM.h"
#elif defined(__18F14K50)
#include "HardwareProfile - Low Pin Count USB Development Kit.h"
#elif defined(__18F13K50)
#elif defined(__18F14K50)
#include "HardwareProfile - Low Pin Count USB Development Kit.h"
#elif defined(__18F46J50)
#include "HardwareProfile - PIC18F46J50 PIM.h"
#if defined(PIC18F_STARTER_KIT_1)
#include "HardwareProfile - PIC18F Starter Kit 1.h"
#else
#include "HardwareProfile - PIC18F46J50 PIM.h"
#endif
#elif defined(__18F47J53)
#include "HardwareProfile - PIC18F47J53 PIM.h"
#endif
Expand Down
3 changes: 0 additions & 3 deletions Firmware/Wiegand to Serial.mcs

This file was deleted.

20 changes: 12 additions & 8 deletions Firmware/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1061,10 +1061,10 @@ void DoWiegandCoversion (void)
if (_gotCard)
{
mLED_4_Off();
RS232_Out_Data[sCount] = 'w';
sCount++;
RS232_Out_Data[sCount] = ' ';
sCount++;
// RS232_Out_Data[sCount] = 'w';
// sCount++;
// RS232_Out_Data[sCount] = ' ';
// sCount++;
RS232_Out_Data[sCount] = '0';
sCount++;
RS232_Out_Data[sCount] = 'x';
Expand Down Expand Up @@ -1155,10 +1155,14 @@ void ProcessIO(void)
//queue. If so, send it out the UART TX pin.
if(RS232_Out_Data_Rdy && mTxRdyUSART())
{
putcUSART(RS232_Out_Data[RS232cp]);
++RS232cp;
if (RS232cp == LastRS232Out)
RS232_Out_Data_Rdy = 0;

// Change this part to send the data to Virtual Serial Port instead of real UART port
putUSBUSART(&RS232_Out_Data[RS232cp],LastRS232Out);

//putcUSART(RS232_Out_Data[RS232cp]);
//++RS232cp;
//if (RS232cp == LastRS232Out)
RS232_Out_Data_Rdy = 0;
}

//Check if we received a character over the physical UART, and we need
Expand Down
47 changes: 38 additions & 9 deletions Firmware/usb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Situational: usb_function_hid.h, usb_function_cdc.h, usb_function_msd.h, etc.
Processor: PIC18 or PIC24 USB Microcontrollers
Hardware: The code is natively intended to be used on the following
hardware platforms: PICDEMFS USB Demo Board,
hardware platforms: PICDEM?FS USB Demo Board,
PIC18F87J50 FS USB Plug-In Module, or
Explorer 16 + PIC24 USB PIM. The firmware may be
modified for use on other USB platforms by editing the
Expand All @@ -15,7 +15,7 @@
Software License Agreement:
The software supplied herewith by Microchip Technology Incorporated
(the “Company”) for its PIC® Microcontroller is intended and
(the “Company? for its PIC?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
Expand All @@ -25,7 +25,7 @@
civil liability for the breach of the terms and conditions of this
license.
THIS SOFTWARE IS PROVIDED IN AN “AS ISCONDITION. NO WARRANTIES,
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,
Expand Down Expand Up @@ -59,7 +59,7 @@
// that use EP0 IN or OUT for sending large amounts of
// application related data.

#define USB_MAX_NUM_INT 1 // For tracking Alternate Setting
#define USB_MAX_NUM_INT 2 // For tracking Alternate Setting

//Device descriptor - if these two definitions are not defined then
// a ROM USB_DEVICE_DESCRIPTOR variable by the exact name of device_dsc
Expand All @@ -80,8 +80,8 @@
//#define USB_PING_PONG_MODE USB_PING_PONG__ALL_BUT_EP0 //NOTE: This mode is not supported in PIC18F4550 family rev A3 devices


//#define USB_POLLING
#define USB_INTERRUPT
#define USB_POLLING
//#define USB_INTERRUPT

/* Parameter definitions are defined in usb_device.h */
#define USB_PULLUP_OPTION USB_PULLUP_ENABLE
Expand Down Expand Up @@ -163,19 +163,48 @@

/* CDC */
#define CDC_COMM_INTF_ID 0x0
#define CDC_COMM_EP 1
#define CDC_COMM_IN_EP_SIZE 8
#define CDC_COMM_EP 1
#define CDC_COMM_IN_EP_SIZE 10

#define CDC_DATA_INTF_ID 0x01
#define CDC_DATA_EP 2
#define CDC_DATA_OUT_EP_SIZE 64
#define CDC_DATA_IN_EP_SIZE 64

#define USB_CDC_SET_LINE_CODING_HANDLER mySetLineCodingHandler
//#define USB_CDC_SUPPORT_HARDWARE_FLOW_CONTROL


//------------------------------------------------------------------------------
//Uncomment the "extra UART signals" that are desired to be enabled/supported.
//These items are optional and none of them are required for basic RX and TX
//USB to UART translator devices.
//If one or more of the below options is enabled however, make sure that the
//polarity is selected correctly, and that the respective pin definitions
//(ex: UART_RTS) and initialization macros (ex: mInitRTSPin()) are present and
//defined correctly in the HardwareProfile - [platform name].h file.
//------------------------------------------------------------------------------
//#define USB_CDC_SUPPORT_DSR_REPORTING //Signal from UART peripheral device, to CDC/USB host. Indicates UART peripheral is ready to receive data and/or commands.
#define USB_CDC_SUPPORT_DTR_SIGNALING //Signal sent from the USB/CDC host, down to the UART peripheral device
//#define USB_CDC_SUPPORT_HARDWARE_FLOW_CONTROL //Implements RTS/CTS UART flow control.

//RTS is GPIO output signal from CDC/USB host micro (indicates UART Rx buffer
// space available, and that the UART peripheral device is free to send data to the USB CDC micro)
//CTS is GPIO input on CDC/USB host micro (allows UART peripheral to tell the
// UART host [the USB micro] not to send anymore Tx data to it for awhile)

//Define the logic level for the "active" state. Setting is only relevant if
//the respective function is enabled. Allowed options are:
//1 = active state logic level is Vdd
//0 = active state logic level is Vss
#define USB_CDC_CTS_ACTIVE_LEVEL 0
#define USB_CDC_RTS_ACTIVE_LEVEL 0
#define USB_CDC_DSR_ACTIVE_LEVEL 0
#define USB_CDC_DTR_ACTIVE_LEVEL 0

//#define USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D2 //Send_Break command
#define USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D1 //Set_Line_Coding, Set_Control_Line_State, Get_Line_Coding, and Serial_State commands
/** DEFINITIONS ****************************************************/

#define TXRX_LED_DELAY 80

#endif //USBCFG_H
13 changes: 8 additions & 5 deletions Firmware/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ state according to the definition in the USB specification.
/* Device Descriptor */
ROM USB_DEVICE_DESCRIPTOR device_dsc=
{
0x12, // Size of this descriptor in bytes
USB_DESCRIPTOR_DEVICE, // DEVICE descriptor type
0x12, // Size of this descriptor in bytes
USB_DESCRIPTOR_DEVICE, // DEVICE descriptor type
0x0200, // USB Spec Release Number in BCD format
CDC_DEVICE, // Class Code
0x00, // Subclass code
0x00, // Protocol code
USB_EP0_BUFF_SIZE, // Max packet size for EP0, see usb_config.h
USB_EP0_BUFF_SIZE, // Max packet size for EP0, see usb_config.h
0x04D8, // Vendor ID
0x000A, // Product ID: CDC RS-232 Emulation Demo
0x0100, // Device release number in BCD format
Expand Down Expand Up @@ -291,13 +291,16 @@ ROM BYTE *ROM USB_CD_Ptr[]=
(ROM BYTE *ROM)&configDescriptor1
};
//Array of string descriptors
ROM BYTE *ROM USB_SD_Ptr[]=
ROM BYTE *ROM USB_SD_Ptr[USB_NUM_STRING_DESCRIPTORS]=
{
(ROM BYTE *ROM)&sd000,
(ROM BYTE *ROM)&sd001,
(ROM BYTE *ROM)&sd002
};

#pragma code
#if defined(__18CXX)
#pragma code
#endif

#endif
/** EOF usb_descriptors.c ****************************************************/
Loading

0 comments on commit 0325d34

Please sign in to comment.