Bluetooth, April Fools and Other Junk

Thanks everyone for your thoughts on some of my recent blog posts – I was quite (pleasantly) surprised to see so many people chipping in with their opinion. It’s good to see everyone’s opinion on the Arduino boards and philosophy and see a good discussion going on.

Earlier this week I spoke on Skype to someone not that far off – only a few hours drive from where I live, in fact – in my very first LUFA support call (as opposed to email, mailing list post or forum post). Quite an experience! My offer to chat with anyone over Skype is still on the table, just keep in mind that I’m shy when it comes to audio, and I’m a geek (my social-skills-fu is lacking). I’ve had some great chats with Andrei over in Russia over the last few weeks, which has been great fun. Andrei also directed me to this great site, which lists all the known VID and PID combinations – a database maintained by the community. Look under the Atmel VID, and you’ll find the LUFA entries I contributed :).

It’s April Fools here, and I was toying with doing something spectacular with the site (replacing content, redirecting, etc.) for a while to celebrate, but got scared of the Google crawler coming by, deciding the site’s changed and heavily personalizing me in the rankings like when I changed over to the new site template. Instead I decided to have some fun with my girlfriend instead, making the entire site redirect to this site and this page instead, but only for her PC at work. The confused emails I got were, ah, interesting.

Last night I decided to knuckle down and get cracking on my incomplete LUFA Bluetooth Host demo again, since I need something to work on, and the code’s languished for over a year now. Originally I stopped due to a lack of commitment to writing a whole L2CAP layer (similar in complexity to TCP/IP) but it’s about time I got back to it and tried to get something working. My ultimate goal will be to make a device capable of establishing a serial link with my PC via bluetooth, using a cheap dongle.

After a lot of re-factoring and cleaning up last night, I’ve got the HCI layer working pretty well, with none of the missed events and fearsome blocking the code used to exhibit. That means I can can pair it with my phone and connect to it – although without a completed L2CAP layer, the phone can’t actually *do* anything with it yet. A typical log session with the new code looks like this at the moment:

Device Attached.
Bluetooth Host Demo running.
Getting Device Data.
Bluetooth Dongle Detected.
Getting Config Data.
Bluetooth Dongle Enumerated.
(HCI) Enter State: Bluetooth_Init_Reset
(HCI) Event Code: 0x0E
(HCI) >> Command Complete (Opcode 0x0c03)
(HCI) Enter State: Bluetooth_Init_ReadBufferSize
(HCI) Event Code: 0x0E
(HCI) >> Command Complete (Opcode 0x1005)
(HCI) Enter State: Bluetooth_Init_SetLocalName
(HCI)  — Name: LUFA Bluetooth Demo
(HCI) Event Code: 0x0E
(HCI) >> Command Complete (Opcode 0x0c13)
(HCI) Enter State: Bluetooth_Init_SetDeviceClass
(HCI) Event Code: 0x0E
(HCI) >> Command Complete (Opcode 0x0c24)
(HCI) Enter State: Bluetooth_Init_WriteScanEnable
(HCI) Event Code: 0x0E
(HCI) >> Command Complete (Opcode 0x0c1a)
(HCI) Event Code: 0x04
(HCI) >> Connection Request from Device 00:26:69:14:D6:DA
(HCI) Enter State: Bluetooth_Conn_AcceptConnection
(HCI) Event Code: 0x0F
(HCI) >> Command Status: 0x00
(HCI) Event Code: 0x03
(HCI) >> Connection Complete to Device 00:26:69:14:D6:DA, Handle 0x0000
(ACL) Packet Received
(ACL) — Connection Handle: 0x0000
(ACL) — Data Length: 0x000C
(ACL) — Destination Channel: 0x0001
(ACL) — Payload Length: 0x0008
(ACL) >> L2CAP Connection Request
(ACL) — PSM: 0x0001
(ACL) — Source Channel: 0x0040
(ACL) Packet Sent
(ACL) — Connection Handle: 0x0000
(ACL) — Data Length: 0x0010
(ACL) — Destination Channel: 0x0001
(ACL) — Payload Length: 0x000C
(ACL) >> L2CAP Connection Response
(ACL) — Source Channel: 0x0040
(ACL) — Destination Channel: 0x0040
(HCI) Event Code: 0x13
(HCI) Event Code: 0x16
(HCI) >> PIN Request from Device 00:26:69:14:D6:DA
(HCI) Enter State: Bluetooth_Conn_SendPINCode
(HCI) — PIN: 0000
(HCI) Event Code: 0x0E
(HCI) >> Command Complete (Opcode 0x040d)
(HCI) Event Code: 0x18
(ACL) Packet Received
(ACL) — Connection Handle: 0x0000
(ACL) — Data Length: 0x000A
(ACL) — Destination Channel: 0x0001
(ACL) — Payload Length: 0x0006
(ACL) — Information Request, Discarded
(ACL) Packet Received
(ACL) — Connection Handle: 0x0000
(ACL) — Data Length: 0x000A
(ACL) — Destination Channel: 0x0001
(ACL) — Payload Length: 0x0006
(ACL) — Information Request, Discarded
(ACL) Packet Received
(ACL) — Connection Handle: 0x0000
(ACL) — Data Length: 0x0010
(ACL) — Destination Channel: 0x0001
(ACL) — Payload Length: 0x000C
(ACL) >> L2CAP Configuration Request
(ACL) — Destination Channel: 0x0040
(ACL) Packet Sent
(ACL) — Connection Handle: 0x0000
(ACL) — Data Length: 0x000F
(ACL) — Destination Channel: 0x0001
(ACL) — Payload Length: 0x000B
(ACL) >> L2CAP Configuration Response
(HCI) Event Code: 0x13
(ACL) Packet Received
(ACL) — Connection Handle: 0x0000
(ACL) — Data Length: 0x0010
(ACL) — Destination Channel: 0x0001
(ACL) — Payload Length: 0x000C
(ACL) >> L2CAP Configuration Request
(ACL) — Destination Channel: 0x0040
(ACL) Packet Sent
(ACL) — Connection Handle: 0x0000
(ACL) — Data Length: 0x000F
(ACL) — Destination Channel: 0x0001
(ACL) — Payload Length: 0x000B
(ACL) >> L2CAP Configuration Response
(HCI) Event Code: 0x13
(HCI) Event Code: 0x05
(HCI) >> Disconnection Complete
(HCI) Enter State: Bluetooth_Init_Reset
(HCI) Event Code: 0x0E
(HCI) >> Command Complete (Opcode 0x0c03)
(HCI) Enter State: Bluetooth_Init_ReadBufferSize
(HCI) Event Code: 0x0E
(HCI) >> Command Complete (Opcode 0x1005)
(HCI) Enter State: Bluetooth_Init_SetLocalName
(HCI)  — Name: LUFA Bluetooth Demo
(HCI) Event Code: 0x0E
(HCI) >> Command Complete (Opcode 0x0c13)
(HCI) Enter State: Bluetooth_Init_SetDeviceClass
(HCI) Event Code: 0x0E
(HCI) >> Command Complete (Opcode 0x0c24)
(HCI) Enter State: Bluetooth_Init_WriteScanEnable
(HCI) Event Code: 0x0E
(HCI) >> Command Complete (Opcode 0x0c1a)

Which is promising – now on to the L2CAP stuff. Wish me luck, since the specs are FREAKING HUGE and fearesomly complex. Time to do my usual trick and just ignore all of it except for the minimum parts needed to get the code properly operational.

 

Comments: 5

Leave a reply »

 
 
 

I didn’t try your new code, but the old bluetooth host was pretty good. I got all the way past the config stage of both L2CAP channels on PS3 bluetooth with no changes.

Have now made some changes and get the full bidirectional HID operation of the PS3 controller over bluetooth.

What is your timescale to change the L2CAP ? There are some timing, fragmentation, and protocol issues to resolve still, just wondered if you plan these in short term, or whether I should make the changes.

Happy to share my ugly carve up of your code if you want.

Great work!

 

Richard,

You should be right to just swap out the old code with the new – at least, for the HCI control layer, as I haven’t had a crack at fixing up the L2CAP code yet. The HCI layer now has a central event processing state (rather than a scattered set of event processing loops) which as a result makes the HCI layer block far less when waiting for a command to complete. It’ll be much easier to extend in the future as well, which is an added bonus.

> Have now made some changes and get the full bidirectional HID operation of the PS3 controller over bluetooth.

Hot diggity! Have you got a link/video? I’ve got a lot of work ahead of me, but I’m amazed you’ve managed to hack something together than actually WORKS when I’ve only scratched the surface of L2CAP.

> What is your timescale to change the L2CAP ? There are some timing, fragmentation, and protocol issues to resolve still, just wondered if you plan these in short term, or whether I should make the changes.

That will be my next main focus, since the rest of the LUFA codebase is just about done (I’ve run out of things to create and extend) so hopefully you’ll be able to see some decent improvements on the L2CAP layer in the next few weeks. My primary focus will be on getting the channel setup/teardown logic working (so that you can make custom Bluetooth devices which can communicate) and then move on to the extras like service discovery, etc.

> Happy to share my ugly carve up of your code if you want.

Absolutely, I’d love to have a look at it.

Cheers!
– Dean

Santiago Saldana
 

Hello, Richard, interesting to see you over on this site. Did you move from the USB shield to using the LUFA project? Its a step I’m planning to make for the next evolution in my own project. I’m eagerly waiting progress as it would be neat to be able to make use of a Wii remote without having to hack it apart. I’ve tested your code so far.

Good luck to both of you!

~Santiago Saldana

 

Hi Dean,

I just wanted to know, how did you get started in programming? What would you recommend for a beginner in programming, any books or websites etc?

Thanks,
Tony

 

Tony,

I had a rough start – I began with an ancient (new back then) AT90S8535 board with no documentation at all, and only a cruddy BASIC compiler for software. It was a Christmas present from my parents, but apparently the guys who designed it did a runner when the manufacturing company (since bankrupt) asked for the documentation. That forced me to learn everything from scratch, from bits and pieces found on the internet. I’ve programmed computers for many years before that (in various “kiddy” languages such as LOGO and VB6) so I eventually settled on the BASCOM BASIC compiler.

Since then lots of fantastic resources have come out, and I’d HIGHLY recommend learning C, plus assembly. The assembly you can pick up from Atmel’s AVR Assembly book, so you can learn to spot poorly optimized sequences from the compiler and correct them, and for C I started with and highly recommend the books from http://www.smileymicros.com. The butterfly board and his book is a nice introduction into the AVR world.

If you’re aiming for something a bit simpler, look into “Arduino” instead, which is a set of tools overlaid on a regular C compiler to make programming quite simple through some basic APIs. That will teach you the basics of programming without getting into the really complicated stuff, and you can transition to “regular” C programming once you’ve become comfortable. Again, there’s a new and (from what I’ve read so far) great book at http://www.smileymicros.com which will help.

Cheers!
– Dean

 

Leave a Reply

 
(will not be published)
 
 
Comment
 
 

 

Vital Stats

  • 35 Years Old
  • Australian
  • Lover of embedded systems
  • Firmware engineer
  • Self-Proclaimed Geek

Latest Blog Posts

RSS