Skip to content

Commit

Permalink
chore: simplified USB controller interface
Browse files Browse the repository at this point in the history
  • Loading branch information
tillt committed Nov 22, 2023
1 parent f4bcfe0 commit 35a6f4e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion KompleteSynthesia/USBController.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ extern const uint32_t kPID_S88MK3;
@property (nonatomic, assign) CGSize screenSize;
@property (nonatomic, assign) unsigned int screenCount;
@property (nonatomic, assign) BOOL connected;
@property (nonatomic, assign) uint32_t deviceInterfaceEndpoint;


+ (NSString*)descriptionWithIOReturn:(IOReturn)code;

- (id)initWithError:(NSError**)error;
- (BOOL)bulkWriteData:(NSData*)data endpoint:(int)endpointNumber error:(NSError**)error;
- (BOOL)bulkWriteData:(NSData*)data error:(NSError**)error;
- (void)teardown;


Expand Down
12 changes: 8 additions & 4 deletions KompleteSynthesia/USBController.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
const uint32_t kPID_S61MK3 = 0x1720; // FIXME: NO IDEA - THESE ARE PLACEHOLDERS SO FAR
const uint32_t kPID_S88MK3 = 0x1730; // FIXME: NO IDEA - THESE ARE PLACEHOLDERS SO FAR

const uint32_t kUSBDeviceInterface = 0x03; // FIXME: Possibly MK2 specific.
const uint32_t kUSBDeviceInterfaceEndpoint = 0x03; // FIXME: Possibly MK2 specific.

@implementation USBController {
IOUSBDeviceInterface942** device;
IOUSBInterfaceInterface942** interface;
Expand All @@ -53,6 +56,7 @@ - (id)initWithError:(NSError**)error
self = [super init];
if (self) {
_connected = NO;
_deviceInterfaceEndpoint = kUSBDeviceInterfaceEndpoint;
//transferActive = 0;
if ([self detectDevice:error] == NULL) {
return nil;
Expand Down Expand Up @@ -267,11 +271,11 @@ - (BOOL)endpoint:(uint8_t)ep pipeRef:(uint8_t*)pipep
return NO;
}

- (BOOL)bulkWriteData:(NSData*)data endpoint:(int)endpointNumber error:(NSError**)error
- (BOOL)bulkWriteData:(NSData*)data error:(NSError**)error
{
assert(data.length > 0);
uint8_t pipeRef;
if ([self endpoint:endpointNumber pipeRef:&pipeRef] == NO) {
if ([self endpoint:_deviceInterfaceEndpoint pipeRef:&pipeRef] == NO) {
NSLog(@"endpoint doesnt exist");
if (error) {
NSDictionary *userInfo = @{
Expand Down Expand Up @@ -355,7 +359,7 @@ - (IOUSBDeviceInterface942**)detectDevice:(NSError**)error

io_registry_entry_t entry = 0;

entry = IORegistryGetRootEntry(kIOMasterPortDefault);
entry = IORegistryGetRootEntry(kIOMainPortDefault);
if (entry == 0) {
return nil;
}
Expand Down Expand Up @@ -480,7 +484,7 @@ - (BOOL)openDevice:(NSError**)error
return NO;
}

ret = [self openDeviceInterface:3];
ret = [self openDeviceInterface:kUSBDeviceInterface];
if (ret != kIOReturnSuccess) {
if (error) {
NSDictionary *userInfo = @{
Expand Down
2 changes: 1 addition & 1 deletion KompleteSynthesia/VideoController.m
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ - (BOOL)drawNIImage:(NIImage*)image screen:(uint8_t)screen x:(unsigned int)x y:(
const unsigned char commandBlob3[] = { 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 };
[stream appendBytes:commandBlob3 length:sizeof(commandBlob3)];

BOOL ret = [usb bulkWriteData:stream endpoint:3 error:error];
BOOL ret = [usb bulkWriteData:stream error:error];

stream.length = 0;

Expand Down

0 comments on commit 35a6f4e

Please sign in to comment.