Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nina: BLE implementation on nina-fw #207

Merged
merged 5 commits into from
Jan 4, 2024
Merged

nina: BLE implementation on nina-fw #207

merged 5 commits into from
Jan 4, 2024

Conversation

deadprogram
Copy link
Member

This PR is to start adding a BLE implementation for boards that use the nina-fw on a connected co-processor.

The only board so far in this PR is the nano-rp2040.

$ tinygo flash -size=short -target=nano-rp2040 -monitor ./examples/scanner
   code    data     bss |   flash     ram
  10824     152    3296 |   10976    3448
Connected to /dev/ttyACM0. Press Ctrl-C to exit.
scanning...
found device: 69:C0:49:32:5B:A5 -94 
found device: 69:C0:49:32:5B:A5 -94 
...

There is still a lot more needed to get an initial implementation complete as a central, but this hopefully is a good starting point.

Copy link
Member

@aykevl aykevl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Overall looking good.

Quick review, focusing mostly on the public API. I haven't really looked at the implementation, assuming you're going to test that one :) (and I don't know much about this BLE firmware anyway).

adapter_nina.go Outdated Show resolved Hide resolved
adapter_nina.go Outdated Show resolved Hide resolved
att.go Outdated Show resolved Hide resolved
att.go Outdated Show resolved Hide resolved
debug.go Show resolved Hide resolved
gap_nina.go Outdated Show resolved Hide resolved
gattc_nina.go Outdated Show resolved Hide resolved
hci.go Outdated Show resolved Hide resolved
gattc_nina.go Outdated Show resolved Hide resolved
@deadprogram
Copy link
Member Author

Making progress:

$ tinygo flash -size short -target nano-rp2040 -tags "ninafw" -monitor -ldflags="-X main.DeviceAddress=57:91:FE:33:10:DC" ./examples/discover/                               
   code    data     bss |   flash     ram                                                                                                                                    
  23504     248    3300 |   23752    3548                                                                                                                                    
Connected to /dev/ttyACM0. Press Ctrl-C to exit.                                                                                                                             
enabling                                                                                                                                                                     
scanning...                                                                                                                                                                  
found device: 42:58:16:B6:05:FB -78                                                                                                                                          
found device: 4C:79:58:04:F5:26 -78                                                                                                                                          
found device: 57:91:FE:33:10:DC -83 Pixel 4a                                                                                                                                 
connected to  57:91:FE:33:10:DC                                                                                                                                              
discovering services/characteristics                                                                                                                                         
- service 01181400-1a00-0018-8600-8d000d180000               
- service 00188600-8d00-0d18-0000-000000000000
- service 0d180000-0000-0000-0000-000000000000
- service ffeeddcc-bbaa-0080-0010-0000a0aa0000
- service 1c180000-0000-0000-0000-000000000000              
Done.

@deadprogram
Copy link
Member Author

Actually my code for the UUIDs for nina was incorrect. However, now I also can discover characteristics 😸

$ tinygo flash -size short -target nano-rp2040 -monitor -ldflags="-X main.DeviceAddress=61:8B:6F:C7:47:68" ./examples/discover/                                                                                                                                                                                              
   code    data     bss |   flash     ram                                                                                                         
  25040     256    3300 |   25296    3556                                                                                                         
Connected to /dev/ttyACM0. Press Ctrl-C to exit.                                                                                                  
enabling                                                                                                                                          
scanning...                                                                                                                                       
found device: 67:EA:32:CA:33:DC -76                                                                                                               
found device: 67:EA:32:CA:33:DC -82                                                                                                               
found device: 61:8B:6F:C7:47:68 -85 Pixel 4a                                                                                                      
connected to  61:8B:6F:C7:47:68                                                                                                                   
discovering services/characteristics                                                                                                              
- service 00001801-0000-1000-8000-00805f9b34fb                                                                                                    
-- characteristic 00002a05-0000-1000-8000-00805f9b34fb                                                                                            
    data bytes 0                                                                                                                                  
    value =                                                                                                                                       
-- characteristic 00002b3a-0000-1000-8000-00805f9b34fb                                                                                            
    data bytes 0                                                                                                                                  
    value =                                                                                                                                       
-- characteristic 00002b29-0000-1000-8000-00805f9b34fb                                                                                            
    data bytes 0                                                                                                                                  
    value =                                                                                                                                       
-- characteristic 00002b2a-0000-1000-8000-00805f9b34fb                                                                                            
    data bytes 0                                                                                                                                  
    value =                                                                                                                                       
- service 00001800-0000-1000-8000-00805f9b34fb                                                                                                                
-- characteristic 00002a00-0000-1000-8000-00805f9b34fb
    data bytes 0                                                                      
    value =     
-- characteristic 00002a01-0000-1000-8000-00805f9b34fb                                                                                                        
    data bytes 0                                                                      
    value =     
-- characteristic 00002aa6-0000-1000-8000-00805f9b34fb                                                                                                        
    data bytes 0                                                                      
    value =                                                                                              
- service 0000180d-0000-1000-8000-00805f9b34fb                                                                                                                
-- characteristic 00002a37-0000-1000-8000-00805f9b34fb                                                                 
    data bytes 0                                                                                         
    value =                                         
-- characteristic 00002a38-0000-1000-8000-00805f9b34fb                                                                                                        
    data bytes 0                                                                                         
    value =                                                
-- characteristic 00002a39-0000-1000-8000-00805f9b34fb                                                                                                        
    data bytes 0                                                                                                       
    value =                                                                                                            
- service 0000aaa0-0000-1000-8000-aabbccddeeff                                                                                                                
-- characteristic 0000aaa1-0000-1000-8000-aabbccddeeff                                                                                                        
    data bytes 0                                                                                                       
    value =                                                
-- characteristic 0000aaa2-0000-1000-8000-aabbccddeeff                                                                                                        
    data bytes 0                                                                                                       
    value =                                                                    
- service 0000181c-0000-1000-8000-00805f9b34fb                                                                                                                
-- characteristic 00002a8a-0000-1000-8000-00805f9b34fb                                                                                                        
    data bytes 0                                                               
    value =                                                                    
-- characteristic 00002a90-0000-1000-8000-00805f9b34fb                                                                                                        
    data bytes 0                                                               
    value =                                                                    
-- characteristic 00002a8c-0000-1000-8000-00805f9b34fb                                                                                                        
    data bytes 0                                                               
    value =                                                                    
Done.

@deadprogram deadprogram marked this pull request as ready for review December 29, 2023 16:51
@deadprogram
Copy link
Member Author

This PR is now ready for further review/merge. @aykevl I have addressed your previous comments.

@deadprogram
Copy link
Member Author

OK, now I also can Read characteristic values:

$ tinygo flash -size short -target nano-rp2040 -monitor -ldflags="-X main.DeviceAddress=40:C4:BE:56:BE:63" ./examples/discover/                                                                                    
   code    data     bss |   flash     ram                                                                                                                                                                          
  26620     272    3300 |   26892    3572                                                                                                                                                                          
Connected to /dev/ttyACM0. Press Ctrl-C to exit.                                                                                                                                                                   
enabling                                                                                                 
scanning...                                                                                                                                                                                                        
found device: 40:C4:BE:56:BE:63 -78 Pixel 4a                                                             
connected to  40:C4:BE:56:BE:63                                                                                                                                                                                    
discovering services/characteristics                                                                     
- service 00001801-0000-1000-8000-00805f9b34fb                                                                                                                                                                     
-- characteristic 00002a05-0000-1000-8000-00805f9b34fb                                                   
     bluetooth: read not supported                                                                       
-- characteristic 00002b3a-0000-1000-8000-00805f9b34fb                                                   
    data bytes 1                                    
    value =                                                                                              
-- characteristic 00002b29-0000-1000-8000-00805f9b34fb                                                   
    data bytes 1                                                                                         
    value =                                                                                              
-- characteristic 00002b2a-0000-1000-8000-00805f9b34fb                                                                                                                                                             
    data bytes 16                                                                                                                                                                                                  
    value = DLtLk                                                                                        
- service 00001800-0000-1000-8000-00805f9b34fb                                                                                                                                                                     
-- characteristic 00002a00-0000-1000-8000-00805f9b34fb                                                   
    data bytes 8                                                                                         
    value = Pixel 4a                                                                                                                                                                                               
-- characteristic 00002a01-0000-1000-8000-00805f9b34fb                                                                                                                                                             
    data bytes 2                                                                                                                                                                                                   
    value =                                                                                                                                                                                                        
-- characteristic 00002aa6-0000-1000-8000-00805f9b34fb                                                   
    data bytes 1                                                                                                                                                                                                   
    value =                                                                                                                                                                                                        
- service 0000180d-0000-1000-8000-00805f9b34fb                                                           
-- characteristic 00002a37-0000-1000-8000-00805f9b34fb                                                                                                                                                             
     bluetooth: read not supported                                                                                                                                                                                 
-- characteristic 00002a38-0000-1000-8000-00805f9b34fb                                                                                                                                                             
    data bytes 1                                                                                                                                                                                                   
    value =                                                                                                                                                                                                        
-- characteristic 00002a39-0000-1000-8000-00805f9b34fb                                                   
     bluetooth: read not supported                                                                                                                                                                                 
- service 0000aaa0-0000-1000-8000-aabbccddeeff                                                                                                                                                                     
-- characteristic 0000aaa1-0000-1000-8000-aabbccddeeff                                                                                                                                                             
    data bytes 2                                                                                                                                                                                                   
    value =                                                                                                                                                                                                        
-- characteristic 0000aaa2-0000-1000-8000-aabbccddeeff                                                                                                                                                             
     bluetooth: read not supported                                                                                                                                                                                 
- service 0000181c-0000-1000-8000-00805f9b34fb                                                                                                                                                                     
-- characteristic 00002a8a-0000-1000-8000-00805f9b34fb                                                   
    data bytes 9                                                                                                                                                                                                   
    value = Natenczas                                                                                                                                                                                              
-- characteristic 00002a90-0000-1000-8000-00805f9b34fb                                                                 
    data bytes 6                                           
    value = Wojski                                         
-- characteristic 00002a8c-0000-1000-8000-00805f9b34fb                                                                 
    data bytes 1                                           
    value =                                                
Done.

@deadprogram
Copy link
Member Author

After a fair bit of effort, can now receive notifications on characteristics:

$ tinygo flash -size short -target nano-rp2040 -monitor -ldflags="-X main.DeviceAddress=5C:DF:97:1D:E4:00" ./examples/heartrate-monitor/
   code    data     bss |   flash     ram
  29252     300    3300 |   29552    3600
Connected to /dev/ttyACM0. Press Ctrl-C to exit.
scanning...
found device: 88:C6:26:9D:A2:56 -79 
found device: 5C:DF:97:1D:E4:00 -72 Pixel 4a
connected to  5C:DF:97:1D:E4:00
discovering services/characteristics
found service 0000180d-0000-1000-8000-00805f9b34fb
found characteristic 00002a37-0000-1000-8000-00805f9b34fb
data: 90
data: 90
data: 90
data: 91
data: 91
data: 92
data: 92

Copy link
Member

@aykevl aykevl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, nothing too major.

I haven't reviewed the implementation very thoroughly, I've looked mostly at the API and consistency with other implementations.

Makefile Outdated Show resolved Hide resolved
adapter_ninafw.go Outdated Show resolved Hide resolved
att_ninafw.go Outdated Show resolved Hide resolved
debug.go Show resolved Hide resolved
gap_ninafw.go Outdated Show resolved Hide resolved
gattc_ninafw.go Outdated Show resolved Hide resolved
gattc_ninafw.go Outdated Show resolved Hide resolved
@deadprogram
Copy link
Member Author

deadprogram commented Jan 3, 2024

I have squashed this down to 2 commits, and rebased against the latest dev. I think it is basically ready enough to merge.

@deadprogram deadprogram force-pushed the nina-ble branch 2 times, most recently from 9c9f594 to 1a90b00 Compare January 3, 2024 19:48
@deadprogram
Copy link
Member Author

@aykevl I ended up adding a commit to this PR to remove some pointer receivers after all.

Copy link
Member

@aykevl aykevl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@aykevl aykevl merged commit b8a4a54 into dev Jan 4, 2024
5 checks passed
@aykevl aykevl deleted the nina-ble branch January 4, 2024 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants