Saturday 25 February 2017

Cypress PSoC VT100 Code Example

Summary
As an alternative interface to one of my projects, basic VT100 functionality was implemented across serial (USB) on a Cypress PSoC4 BLE device. The Cypress iprintf code was used with a wrapper to implement basic VT100 features.

The screen capture below shows basic control of text and colour.

VT100 Example in TeraTerm
VT100 Example in TeraTerm

As a starting reference the
Bash Hackers website was used for the VT100 escape codes. A plethora of information can be found at sites such as Technopedia, TermSys, NorthEastern Uni, ASCII-Table and ISP to name a handful. What has been provided is only a portion of the total VT100 commands available.

Code for the PSoC
For Cypress Creator development environment a separate VT100 source and header file were created with the necessary escape commands.


VT100 Commands
VT100 Commands
Foreground and background colors.


VT100 Colours
VT100 Colours

Cypress already provide a PSoC Creator example project with iprintf, which works effectively as the low level interface. A reference to this library was included in VT100 code.

To use a number of commands at once or to configure the location of the cursor a few functions were written, prototypes below. There is room to improve these functions but for testing they function as required.


VT100 Function Prototypes
VT100 Function Prototypes

Usage in the software main shown below.

VT100 Example Usage
VT100 Example Usage


Testing
Testing was also performed with other terminal packages such as PuTTY and RealTerm.

VT100 Example in PuTTY (Windows)
VT100 Example in PuTTY (Windows)
TermPuTTY under Ubuntu Mate, customised settings

VT100 Example in PuTTY (Ubuntu Mate)
VT100 Example in PuTTY (Ubuntu Mate)

RealTerm was placed in ANSI mode with good results, except for the colours.

VT100 Example in RealTerm
VT100 Example in RealTerm

Downloads


vt100.c
vt100.c

vt100.h
vt100.h



Change Summary

Version 1.02 (15 March 2017)
  • Added GPL details
  • Corrected two text command enumerations
  • Updated PSoC Creator project
Version 1.01 (11 March 2017)
  • Added defines for background colour
  • Changed names of foreground colour defines
  • Updated PSoC Creator project
Version 1.00 (26 February 2017)
  • Created PSoC Creator project for initial vt100 commands


Wednesday 15 February 2017

MCP23S17 IO Port Expander Header File / Register

Summary
For a recent project the 16bit IO Expander, MCP23S17, from Microchip was enlisted for low voltage input scanning. 

Searching online, at the time of writing this blog, there were no projects using this part with sample code. 

Below is the header file that may be of use.


MCP23S17 Microchip IO Expander QFN Package
Microchip IO Expander QFN Package


Downloads


mcp23s17.h

Code


/******************************
* mcp23s17.h
******************************/

#ifndef mcp23s17_h
#define mcp23s17_h

typedef unsigned char   uint8;
    
#define MCP_READ   0x41     /* Read */
#define MCP_WRITE   0x40     /* Write */
#define Mode_8Bit     1         /* Addressing 8/16bit */
#define Mode_16bit    0

#ifdef Mode_16Bit
    /******************************
    * Control register for BANK=0
    ******************************/
    #define IODIRA        0x00      /* Data Direction Register for PORTA */
    #define IODIRB        0x01      /* Data Direction Register for PORTB */ 
    #define IPOLA         0x02      /* Input Polarity Register for PORTA */ 
    #define IPOLB         0x03      /* Input Polarity Register for PORTB */ 
    #define GPINTENA      0x04      /* Interrupt-on-change enable Register for PORTA */ 
    #define GPINTENB      0x05      /* Interrupt-on-change enable Register for PORTB */ 
    #define DEFVALA       0x06      /* Default Value Register for PORTA */    
    #define DEFVALB       0x07      /* Default Value Register for PORTB */      
    #define INTCONA       0x08      /* Interrupt-on-change control Register for PORTA */  
    #define INTCONB       0x09      /* Interrupt-on-change control Register for PORTB */      
    #define IOCON         0x0A      /* Configuration register for device */                      
    #define GPPUA         0x0C      /* 100kOhm pullup resistor register for PORTA (sets pin to input when set) */    
    #define GPPUB         0x0D      /* 100kOhm pullup resistor register for PORTB (sets pin to input when set) */      
    #define INTFA         0x0E      /* Interrupt flag Register for PORTA */        
    #define INTFB         0x0F      /* Interrupt flag Register for PORTB */    
    #define INTCAPA       0x10      /* Interrupt captured value Register for PORTA */  
    #define INTCAPB       0x11      /* Interrupt captured value Register for PORTB */    
    #define GPIOA         0x12      /* General purpose I/O Register for PORTA */  
    #define GPIOB         0x13      /* General purpose I/O Register for PORTB */ 
    #define OLATA         0x14      /* Output latch Register for PORTA */ 
    #define OLATB         0x15      /* Output latch Register for PORTB */
#endif

#ifdef Mode_8Bit
    /******************************
    * Control register for BANK=1
    ******************************/
    #define IODIRA        0x00      /* Data Direction Register for PORTA */
    #define IPOLA         0x01      /* Input Polarity Register for PORTA */  
    #define GPINTENA      0x02      /* Interrupt-on-change enable Register for PORTA */     
    #define DEFVALA       0x03      /* Default Value Register for PORTA */    
    #define INTCONA       0x04      /* Interrupt-on-change control Register for PORTA */     
    #define IOCONA        0x05      /* Configuration register for device */          
    #define GPPUA         0x06      /* 100kOhm pullup resistor register for PORTA (sets pin to input when set) */     
    #define INTFA         0x07      /* Interrupt flag Register for PORTA */
    #define INTCAPA       0x08      /* Interrupt captured value Register for PORTA */
    #define GPIOA         0x09      /* General purpose I/O Register for PORTA */  
    #define OLATA         0x0A      /* Output latch Register for PORTA */ 
    #define IODIRB        0x10      /* Data Direction Register for PORTB */ 
    #define IPOLB         0x11      /* Input Polarity Register for PORTB */ 
    #define GPINTENB      0x12      /* Interrupt-on-change enable Register for PORTB */
    #define DEFVALB       0x13      /* Default Value Register for PORTB */      
    #define INTCONB       0x14      /* Interrupt-on-change control Register for PORTB */
    #define IOCONB        0x15      /* Configuration register for device */  
    #define GPPUB         0x16      /* 100kOhm pullup resistor register for PORTB (sets pin to input when set) */        
    #define INTFB         0x17      /* Interrupt flag Register for PORTB */    
    #define INTCAPB       0x18      /* Interrupt captured value Register for PORTB */    
    #define GPIOB         0x19      /* General purpose I/O Register for PORTB */ 
    #define OLATB         0x1A      /* Output latch Register for PORTB */
#endif
    
/* Config bits - IOCON */
#define BANK  0x80
#define MIRROR  0x40
#define SEQOP  0x20
#define DISSLW  0x10
#define HAEN  0x08
#define ODR      0x04
#define INTPOL  0x02

/******************************
* Prototypes
******************************/
void MCP23S17_init();
void MCP23S17_write(uint8 address, uint8 value);
uint8 MCP23S17_read(uint8 address);
uint8 MCP23S17_verify(uint8 address, uint8 verify_data);
    
#endif
/* END */



Change Summary

Version 1.00 (10 February 2017)

  • Created register mapping for MCP23S17, 8 and 16 bit modes