One thing I noticed, in your pwm function, you pass in a variable period (which is in some strange units [0.2 = 2ms] 100ms?) then you use the same variable name for the integer value (in nanoseconds). It seems to work, but might be confusing to people reusing your code.
I think it might be best to have the variable sent to be in milliseconds, and then use a different variable name for the integer value that written to the period file.