Author Topic: USB Host controller project  (Read 7945 times)

0 Members and 3 Guests are viewing this topic.

Offline gmcTopic starter

  • Regular Contributor
  • *
  • Posts: 145
  • Country: gb
USB Host controller project
« on: January 09, 2020, 10:38:20 am »
I'm looking at starting a new project which will allow a PC usb keyboard to be connected to a microcontroller and this will interface with a retro Commodore 64 computer. The end goal is to use a normal usb keyboard in place of the C64 keyboard.

The C64 keyboard is controlled via a 8x8 matrix. 8 rows and 8 columns.

So I'm thinking of using a at90usb162 to read the keys from the USB keyboard and then interfacing into the C64 with a MT8816AE (8 x 16 Analog Switch Array)
https://www.futurlec.com/Datasheet/Zarlink/MT8816AE.pdf

Does this sound do-able? I've seen a few examples of using the at90usb162 as a usb host controller and I think this will be the trickiest part of the project. The at90usb162 should also have enough pins to control the MT8816AE


 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17861
  • Country: fr
Re: USB Host controller project
« Reply #1 on: January 09, 2020, 03:48:18 pm »
Are you sure this MCU can do USB host? I'm not so sure.
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 8072
  • Country: pl
Re: USB Host controller project
« Reply #2 on: January 09, 2020, 04:50:22 pm »
I'm absolutely sure it can't, unless somebody wrote a bitbanging implementation good for maybe low speed. But if you go up the line, there are AT90USB parts with OTG capability and they have more pins. They are expensive and some ARM may be cheaper.

For the lowest effort solution use Raspberry Pi ;D

And, frankly, look around because somebody may have already done similar project like translating USB to PS/2 or whatever.
« Last Edit: January 09, 2020, 04:52:36 pm by magic »
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17861
  • Country: fr
Re: USB Host controller project
« Reply #3 on: January 09, 2020, 04:56:36 pm »
I'm pretty sure USB to PS/2 converters do exist (to use USB keyboards on old computers), and probably pretty cheap too. So all you'd need is one of these, and design just the PS/2 to C64 adapter, which should be pretty straightforward even on a very small MCU. Additional benefit, outside of simplicity, is that it could of course be used stand-alone with PS/2 keyboards, which can also still be found (a lot of used ones, and probably some new ones as well...)
 

Offline oPossum

  • Super Contributor
  • ***
  • Posts: 1559
  • Country: us
  • Very dangerous - may attack at any time
Re: USB Host controller project
« Reply #4 on: January 09, 2020, 05:26:13 pm »
CH559 has USB host and USB bootloader (no programmer needed)


[note: not my video]
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 5854
  • Country: dk
Re: USB Host controller project
« Reply #5 on: January 09, 2020, 05:49:31 pm »
I'm pretty sure USB to PS/2 converters do exist (to use USB keyboards on old computers), and probably pretty cheap too. So all you'd need is one of these, and design just the PS/2 to C64 adapter, which should be pretty straightforward even on a very small MCU. Additional benefit, outside of simplicity, is that it could of course be used stand-alone with PS/2 keyboards, which can also still be found (a lot of used ones, and probably some new ones as well...)

I believe most of those USB keyboard to PS/2  connector were passive and the keyboards supported both USB and PS/2 on the same wires. I don't know if "modern" keyboards still do that
 

Offline gmcTopic starter

  • Regular Contributor
  • *
  • Posts: 145
  • Country: gb
Re: USB Host controller project
« Reply #6 on: January 09, 2020, 06:20:30 pm »
Thanks for the replies. I wrongly assumed the at90usb162 would work as a usb host. I'll have a look at the other models that support  OTG. Will also check out the CH559.

There are other alternatives. I could use a RPi or a Arduino Due, or some other type of usb host shield but I would like to build everything on a single PCB so I can start selling a few devices. Going to be trickier if I have to get all these extra modules and solder them onto the PCB.

 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 8354
  • Country: fi
    • My home page and email address
Re: USB Host controller project
« Reply #7 on: January 09, 2020, 06:23:37 pm »
Use a proper USB host controller instead.  If you use MAX3421E, you can interface it to your microcontroller via SPI, and you can use or look at existing Arduino USB Host Shield libraries for software implementation.

Note MAX3421E runs at 3.3V signal levels only.  You can try it with the cheap Mini USB Host Shields on fleabay and elsewhere, just make sure you either use a 3.3V supply and signal level microcontroller, or use a level shifter and a 3.3V regulator for the SPI connection between MAX3421E and your microcontroller.

If I was making my own board, I'd use AVR (I like ATmega32u4), 2+2 dual supply translating unidirectional transceivers (I dunno, maybe 74LVC1T?), MAX3421E, a 3.3V regulator, a 16 MHz crystal if the AVR wants it, and a smattering of passives, plus the MT8816AE of course.
« Last Edit: January 09, 2020, 06:30:20 pm by Nominal Animal »
 
The following users thanked this post: gmc

Offline GromBeestje

  • Frequent Contributor
  • **
  • Posts: 310
  • Country: nl
Re: USB Host controller project
« Reply #8 on: January 09, 2020, 06:35:41 pm »
The AT90USB647 and AT90USB1287 have host support.
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17861
  • Country: fr
Re: USB Host controller project
« Reply #9 on: January 09, 2020, 07:04:42 pm »
I'm pretty sure USB to PS/2 converters do exist (to use USB keyboards on old computers), and probably pretty cheap too. So all you'd need is one of these, and design just the PS/2 to C64 adapter, which should be pretty straightforward even on a very small MCU. Additional benefit, outside of simplicity, is that it could of course be used stand-alone with PS/2 keyboards, which can also still be found (a lot of used ones, and probably some new ones as well...)

I believe most of those USB keyboard to PS/2  connector were passive and the keyboards supported both USB and PS/2 on the same wires. I don't know if "modern" keyboards still do that

Right! I don't know for *all* more recent keyboards either, but keyboards supporting both USB and PS/2 are still sold.

Now that we know the OP wants to probably make a product, I can understand this two-part solution could be clunky, although still usable, and limiting the potential buyers.

So now the rest will largely depend on the OP's skills and the targeted cost. Any MCU supporting USB OTG should do it. Try and select one for which there's already example code to support USB HID devices.

You can take a look a this: https://felis.github.io/USB_Host_Shield_2.0/
(library that Nominal Animal talked about.)
 
The following users thanked this post: gmc

Online langwadt

  • Super Contributor
  • ***
  • Posts: 5854
  • Country: dk
Re: USB Host controller project
« Reply #10 on: January 09, 2020, 07:21:16 pm »
I'm pretty sure USB to PS/2 converters do exist (to use USB keyboards on old computers), and probably pretty cheap too. So all you'd need is one of these, and design just the PS/2 to C64 adapter, which should be pretty straightforward even on a very small MCU. Additional benefit, outside of simplicity, is that it could of course be used stand-alone with PS/2 keyboards, which can also still be found (a lot of used ones, and probably some new ones as well...)

I believe most of those USB keyboard to PS/2  connector were passive and the keyboards supported both USB and PS/2 on the same wires. I don't know if "modern" keyboards still do that

Right! I don't know for *all* more recent keyboards either, but keyboards supporting both USB and PS/2 are still sold.

Now that we know the OP wants to probably make a product, I can understand this two-part solution could be clunky, although still usable, and limiting the potential buyers.

if keyboards still support both USB and PS/2 the converter can be skipped, just use a USB connector  directly for the PS/2

 

Offline gmcTopic starter

  • Regular Contributor
  • *
  • Posts: 145
  • Country: gb
Re: USB Host controller project
« Reply #11 on: January 09, 2020, 07:46:40 pm »
The MAX3421E looks very interesting. Need to put some costs together but it will either be a Atmel with OTG support, or a simpler Atmel in combination with the MAX3421.

Great link you posted for the USB host shield 2.0
 

Offline nigelwright7557

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: gb
    • PCBCAD software
Re: USB Host controller project
« Reply #12 on: January 09, 2020, 09:56:14 pm »
There are numerous PIC microcontrollers that do USB hosting.
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 4037
  • Country: 00
Re: USB Host controller project
« Reply #13 on: January 09, 2020, 11:06:23 pm »
There are numerous STM32 microcontrollers that can do a USB host or two.  Source code examples for USB HID (both keyboard and mouse) readily available.
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 8354
  • Country: fi
    • My home page and email address
Re: USB Host controller project
« Reply #14 on: January 10, 2020, 10:11:14 am »
The reason I suggested such a complicated arrangement of hardware (ATmega32U4, MT8816AE, MAX3421E, 3.3V regulator, SPI level shifter between 32u4 and MAX3421E, a crystal for the 32u4, and a smattering of passives), is that I know the needed software already exists -- with the exception of mapping keypresses and releases to control the MT8816AE, and that looks very straightforward.  You can even build an Arduino test rig and try it right now, using a cheap Pro Micro clone (just remember to select Arduino Leonardo in the Arduino environment!), an USB host shield, a 3.3V regulator (breadboard module), 3.3V-5V level shifters between the clone and the USB host shield, plus a MT8816AE. All those are available on fleabay (I checked), and in DIP versions, so you can breadboard it.

A 32-bit ARM microcontroller with USB host support would be electronically simpler (and cost much less in parts), as you'd probably only need some level shifters (they typically use 3.3V logic, and I believe the C64 uses 5V internally) to the MT8816AE and omit the USB host controller chip, but I believe the software side would need a lot more work, as the existing sources would not be usable as-is.  (Unless, as Yansi said, there exists examples in the STM32 land and you use one; I would not know about those.  I am only talking about the Arduino, and bare-metal/avr-gcc + avr-libc world here, without any hardware abstraction libraries.  The Arduino libraries are surprisingly easy to modify to work on plain-metal avr-gcc, if bare-metal is your goal.)

Because of this, I believe that the ATmega32u4 -based solution is "better" in terms of overall value, especially as the target audience is one that probably values the easy customization/modification of the board.  There is nothing stopping one (but the fear/probability of others cloning the board) from keeping the custom device programmable in the Arduino environment, for example.

(Of course, here we get into the business logic, which I fail.  If the idea is to do this for fun and not for commercial gain, then the openness/ease of modification should be a win-win.  If the idea is to make a small profit too, then.. well, I wouldn't know, my suggestion is utterly unlikely to yield that.)
« Last Edit: January 10, 2020, 10:13:47 am by Nominal Animal »
 
The following users thanked this post: gmc

Offline gmcTopic starter

  • Regular Contributor
  • *
  • Posts: 145
  • Country: gb
Re: USB Host controller project
« Reply #15 on: January 10, 2020, 04:07:54 pm »
I'm going to go with the max3421e route. Been using Arduino's for years and very familiar with programming them. There is also a decent library available which I have started looking through.

I've ordered a MAX3421e and MT8816AE and will play around with them on my Arduino Uno.  Once it all works will build everything on a PCB.

As you said there are many ways to do this. A  STM32 might be simpler with fewer components but might take me 10x longer to work out how to program it :)

The idea is to mainly to build a board for myself and a few friends, learn on the way (And hopefully not blow up my C64) and maybe sell off a few extras. Not looking to go big.
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17861
  • Country: fr
Re: USB Host controller project
« Reply #16 on: January 10, 2020, 04:15:38 pm »
The reason I suggested such a complicated arrangement of hardware (ATmega32U4, MT8816AE, MAX3421E, 3.3V regulator, SPI level shifter between 32u4 and MAX3421E, a crystal for the 32u4, and a smattering of passives), is that I know the needed software already exists.

Fully agree with this. And I don't like Arduino much, but here the existing *working* code base is a very big plus.
Disclaimer: I haven't looked thoroughly at the library itself, but it should work on several MCUs that are supported by the Arduino environment I guess? So you're not even necessarily stuck to using an Atmega if you want something a bit more powerful, or cheaper, or whatever?

The software side of this should not be underestimated. Sure it only takes a few seconds to just write: "any MCU with OTG will do". It's another story to get a working, robust solution, that will work with all keyboards without weird compatibility issues and that will not require hours of debugging. Anyone thinking that random example code (even code that's from the vendor! it's often pure crap!) will do is IMO sadly mistaken.
« Last Edit: January 10, 2020, 05:59:41 pm by SiliconWizard »
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 8354
  • Country: fi
    • My home page and email address
Re: USB Host controller project
« Reply #17 on: January 10, 2020, 05:28:15 pm »
I haven't looked thoroughly at the library itself, but it should work on several MCUs that are supported by the Arduino environment I guess?
Yes; the github page for the USB Host Shield 2.0 library says, paraphrased: all official Arduino AVR boards, Arduino Due, Intel Galileo, Intel Galileo 2, Intel Edison, Teensy 2.0/2.0++/LC/3.x, Balanduino, Sanguino, Black Widdow, RedBearLab nRF51822, Digilent chipKIT, STM32F4, ESP8266, and ESP32.

That obviously includes clones like Pro Micros (clones of Arduino Pro Micro or SparkFun Pro Micro, normally with an Arduino Leonardo bootloader, and should be treated as an Arduino Leonardo in the Arduino environment).
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17861
  • Country: fr
Re: USB Host controller project
« Reply #18 on: January 10, 2020, 06:01:41 pm »
I haven't looked thoroughly at the library itself, but it should work on several MCUs that are supported by the Arduino environment I guess?
Yes; the github page for the USB Host Shield 2.0 library says, paraphrased: all official Arduino AVR boards, Arduino Due, Intel Galileo, Intel Galileo 2, Intel Edison, Teensy 2.0/2.0++/LC/3.x, Balanduino, Sanguino, Black Widdow, RedBearLab nRF51822, Digilent chipKIT, STM32F4, ESP8266, and ESP32.

That obviously includes clones like Pro Micros (clones of Arduino Pro Micro or SparkFun Pro Micro, normally with an Arduino Leonardo bootloader, and should be treated as an Arduino Leonardo in the Arduino environment).

A handful indeed. With the ones supporting Bluetooth, you could even design the adapter so that it can also work with Bluetooth keyboards. ;D
 
The following users thanked this post: Nominal Animal

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 8354
  • Country: fi
    • My home page and email address
Re: USB Host controller project
« Reply #19 on: January 10, 2020, 06:35:50 pm »
Not a bad idea!  If you used ESP32, you could support both USB and Bluetooth in the same device!  ESP32's are certainly cheap enough.

(You would need to use 3.3V to 5V voltage shifter between the ESP32 and the MT8816AE, though, as ESP32 uses 3.3V logic levels. Standard level shifters work, all the signals are one-directional. No level shifter needed between ESP32 and the USB Host Shield 2.0.  I do believe this is an even better suggestion than my ATmega32u4 -based one.)

Note: I haven't used Bluetooth HID, but AIUI it's just a wrapper around the USB HID protocol, so it should not be too much extra work to support both.  I would also have both interfaces their own state, so that one could use two keyboard simultaneously.  (That is, MT8816AE would be controlled by every press and release event on either keyboard; you do not need to remember the MT8816AE states.)

Also, I only just noticed that the USB Host Shield 2.0 library even has a keyboard example; surely useful here.

Oh, and an additional note: do consider using the extra pins left over for optionally controlling the joystick ports as well.
« Last Edit: January 10, 2020, 06:43:04 pm by Nominal Animal »
 

Offline dreamwatcher

  • Newbie
  • Posts: 7
  • Country: us
Re: USB Host controller project
« Reply #20 on: May 27, 2022, 03:24:51 pm »
I am really late to the party with this post. ;D

However, I have been working on just this type pf project for a few years.

https://github.com/Hartland/C64-Keyboard

This project includes both PS/2 and USB keyboards.

For USB, as I suggest in the README, use a SEEED XIAO, though the project does include a DUE, it is WAY overkill for the project.
For PS/2 use an UNO or Nano.

Perhaps you are already well along the way on your own project and my project can help with some issues you are having.
 


Offline robert.rozee

  • Frequent Contributor
  • **
  • Posts: 385
  • Country: nz
Re: USB Host controller project
« Reply #22 on: May 31, 2022, 01:37:16 pm »
you may also like to have a look at the CH376, available on a small PCB for around $5 on ebay:
https://www.ebay.com/itm/165027473834

while the main target is reading USB flash drives, it appears to also produce results from USB keyboards and mouses. it can connect directly to a TTL serial port, and requires to be sent commands and returns packets of data containing keypress information - NOT ASCII codes; some interpretation is required. for projects using it see:
https://github.com/djuseeq/Ch376msc/issues/13
and:
http://www.electronicsfaq.com/2016/11/interface-usb-mouse-to-your-arduino.html

i have a couple of the ebay boards on order, and am hoping to be able to come up with the incantations necessary to configure it and then repeatedly prompt for reports of keyboard state (up to 6-key rollover, shift states, etc). there appears to be a wch-ic.com forum somewhere where folks have been able to obtain useful guidance in english.


cheers,
rob   :-)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->