- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Although I posted a sample for CY8CKIT-059 a few days ago, to make it easier to find this for TSoC user I'm posting this.
数日前に CY8CKIT-059 用のサンプルをポストしましたが、TSoC 用に見つけやすいように別にポストさせていただきます。
In another topic, I encountered the following I2C keyboard while discussing a keyboard for PSoC.
別のスレで PSoC に繋ぐことのできるキーボードという話をしていたところ下記の I2C キーボードに遭遇しました。
The CardKb
I ordered mine from Switch Science
私は自分用にスイッチサイエンスさんからポチらせていただきました。
https://www.switch-science.com/catalog/5689/
This keyboard is surely not for a long text typing, but having full keyboard input capability for a MCU is nice.
長文を打つのに向いているとは言えませんが、MCU 用に手軽なフルキーボードがあるのは便利です。
schematic
Pins
Tera Term log
main.c
=============
#include "project.h"
#include "stdio.h"
#define CARDKB_I2C_SLAVE_ADDR 0x5F
#define I2C_TIMEOUT_MS 500
#define STR_LEN 64
char str[STR_LEN+1] ;
void print(char *str)
{
UART_UartPutString(str) ;
}
void printc(char c)
{
UART_UartPutChar(c) ;
}
void cls(void)
{
print("\033c") ; /* reset */
CyDelay(20) ;
print("\033[2J") ; /* clear screen */
CyDelay(20) ;
}
void splash(void)
{
cls() ;
print("TSoC CardKb Test") ;
snprintf(str, STR_LEN, "(%s %s)\n", __DATE__, __TIME__) ;
print(str) ;
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
splash() ;
I2C_Start() ;
}
uint8_t myI2C_ReadByte(uint8_t reg_addr)
{
uint8_t status ;
uint8_t value = 0 ;
I2C_ClearPendingInt();
status = I2C_I2CMasterSendStart(CARDKB_I2C_SLAVE_ADDR, I2C_I2C_WRITE_XFER_MODE, I2C_TIMEOUT_MS) ;
if (I2C_I2C_MSTR_NO_ERROR == status) {
I2C_I2CMasterWriteByte(reg_addr, I2C_TIMEOUT_MS);
status = I2C_I2CMasterSendRestart(CARDKB_I2C_SLAVE_ADDR, I2C_I2C_READ_XFER_MODE, I2C_TIMEOUT_MS);
}
if (I2C_I2C_MSTR_NO_ERROR == status) {
status = I2C_I2CMasterReadByte(I2C_I2C_ACK_DATA, &value, I2C_TIMEOUT_MS);
}
I2C_I2CMasterSendStop(I2C_TIMEOUT_MS);
return(value) ;
}
uint8_t read_cardkb(void)
{
uint8_t key = 0 ;
key = myI2C_ReadByte(1) ;
return( key ) ;
}
int main(void)
{
uint8_t key ;
init_hardware() ;
for(;;)
{
key = read_cardkb() ;
if (key) {
// snprintf(str, STR_LEN, "%02X ", key) ;
// print(str) ;
printc(key) ;
}
CyDelay(10) ;
}
}
=============
moto
- Labels:
-
ispn:39618:1:0
-
l1:314:1:0
-
PSoC345LP